mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-08 13:03:10 +02:00
Mail validation in frontend and backend unified
Pushed-by: Florian Scholdei<florian.scholdei@cloudogu.com> Co-authored-by: Florian Scholdei<florian.scholdei@cloudogu.com>
This commit is contained in:
2
gradle/changelog/mail_regex.yaml
Normal file
2
gradle/changelog/mail_regex.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: fixed
|
||||
description: Mail validation in front- and backend unified
|
||||
@@ -31,7 +31,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
public final class ValidationUtil {
|
||||
|
||||
private static final String REGEX_MAIL = "^[A-Za-z0-9][\\w.-]*@[A-Za-z0-9][\\w\\-\\.]*\\.[A-Za-z0-9][A-Za-z0-9-]+$";
|
||||
private static final String REGEX_MAIL = "^[a-z0-9!#$%&'*+\\/=?^_`{|}~\" -]+(?:\\.[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$";
|
||||
|
||||
public static final String REGEX_NAME = "^(?:(?:[^:/?#;&=\\s@%\\\\][^:/?#;&=%\\\\]*[^:/?#;&=\\s%\\\\])|(?:[^:/?#;&=\\s@%\\\\]))$";
|
||||
|
||||
@@ -75,7 +75,7 @@ public final class ValidationUtil {
|
||||
* @return {@code true} if mail is valid
|
||||
*/
|
||||
public static boolean isMailAddressValid(String mail) {
|
||||
return Util.isNotEmpty(mail) && mail.matches(REGEX_MAIL);
|
||||
return Util.isNotEmpty(mail) && mail.toLowerCase().matches(REGEX_MAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,7 +87,15 @@ class ValidationUtilTest {
|
||||
"s.sdorra@t.co",
|
||||
"s.sdorra@ucla.college",
|
||||
"s.sdorra@example.xn--p1ai",
|
||||
"s.sdorra@scm.solutions" // issue 909
|
||||
"s.sdorra@scm.solutions", // issue 909
|
||||
"s'sdorra@scm.solutions",
|
||||
"\"S Sdorra\"@scm.solutions",
|
||||
"A@BC.DE",
|
||||
"x@example.com",
|
||||
"example@s.example",
|
||||
"user.name+tag+sorting@example.com",
|
||||
"name/surname@example.com",
|
||||
"user%example.com@example.org"
|
||||
})
|
||||
void shouldAcceptMailAddress(String value) {
|
||||
assertTrue(ValidationUtil.isMailAddressValid(value));
|
||||
@@ -101,7 +109,10 @@ class ValidationUtilTest {
|
||||
"s.sdorra@ostfalia",
|
||||
"s.sdorra@@ostfalia.de",
|
||||
"s.sdorra@ ostfalia.de",
|
||||
"s.sdorra @ostfalia.de"
|
||||
"s.sdorra @ostfalia.de",
|
||||
"s.sdorra@[ostfalia.de",
|
||||
"abc.example.com",
|
||||
"a@b@c@example.com"
|
||||
})
|
||||
void shouldRejectMailAddress(String value) {
|
||||
assertFalse(ValidationUtil.isMailAddressValid(value));
|
||||
@@ -180,19 +191,19 @@ class ValidationUtilTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"scm",
|
||||
"scm-",
|
||||
"scm_",
|
||||
"s_cm",
|
||||
"s-cm",
|
||||
"s",
|
||||
"sc",
|
||||
".hiddenrepo",
|
||||
"b.",
|
||||
"...",
|
||||
"..c",
|
||||
"d..",
|
||||
"a..c"
|
||||
"scm",
|
||||
"scm-",
|
||||
"scm_",
|
||||
"s_cm",
|
||||
"s-cm",
|
||||
"s",
|
||||
"sc",
|
||||
".hiddenrepo",
|
||||
"b.",
|
||||
"...",
|
||||
"..c",
|
||||
"d..",
|
||||
"a..c"
|
||||
})
|
||||
void shouldAcceptRepositoryName(String path) {
|
||||
assertTrue(ValidationUtil.isRepositoryNameValid(path));
|
||||
|
||||
@@ -91,8 +91,12 @@ describe("test mail validation", () => {
|
||||
"@ostfalia.de",
|
||||
"s.sdorra@",
|
||||
"s.sdorra@ostfalia",
|
||||
"s.sdorra@@ostfalia.de",
|
||||
"s.sdorra@ ostfalia.de",
|
||||
"s.sdorra @ostfalia.de",
|
||||
"s.sdorra@[ostfalia.de",
|
||||
"abc.example.com",
|
||||
"a@b@c@example.com"
|
||||
];
|
||||
for (const mail of invalid) {
|
||||
it(`should return false for '${mail}'`, () => {
|
||||
@@ -112,6 +116,12 @@ describe("test mail validation", () => {
|
||||
"s.sdorra@scm.solutions",
|
||||
"s'sdorra@scm.solutions",
|
||||
'"S Sdorra"@scm.solutions',
|
||||
"A@BC.DE",
|
||||
"x@example.com",
|
||||
"example@s.example",
|
||||
"user.name+tag+sorting@example.com",
|
||||
"name/surname@example.com",
|
||||
"user%example.com@example.org"
|
||||
];
|
||||
for (const mail of valid) {
|
||||
it(`should return true for '${mail}'`, () => {
|
||||
|
||||
@@ -36,7 +36,7 @@ export const isBranchValid = (name: string) => {
|
||||
return branchRegex.test(name);
|
||||
};
|
||||
|
||||
const mailRegex = /^[ -~]+@[A-Za-z0-9][\w\-.]*\.[A-Za-z0-9][A-Za-z0-9-]+$/;
|
||||
const mailRegex = /^[a-z0-9!#$%&'*+\/=?^_`{|}~" -]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;
|
||||
|
||||
export const isMailValid = (mail: string) => {
|
||||
return mailRegex.test(mail);
|
||||
|
||||
Reference in New Issue
Block a user