Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-65230] Remove the regexp check on emails #99

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ private EmailValidator() {
throw new UnsupportedOperationException("Cannot instantiate utility class");
}

static boolean isValid(@NonNull String email) {
Matcher matcher = PATTERN.matcher(email);
return matcher.matches();
}

public static boolean isValidEmail(String value) {
String emailAddress = EmailUtil.fixEmptyAndTrimAllSpaces(value);
return StringUtils.isNotBlank(emailAddress) && isValid(emailAddress);
return StringUtils.isNotBlank(emailAddress);
}

public static FormValidation validateEmail(String value) {
Expand All @@ -39,9 +34,6 @@ public static FormValidation validateEmail(String value) {
return FormValidation.error(
"Email cannot contain illegal character ';' or ','. Consider using the CC fields if multiple recipients are required");
}
if (!isValid(emailAddress)) {
return FormValidation.error("Invalid email");
}
return FormValidation.ok();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public void testInstanceBadEmail() throws Exception {
cc.add(new Scalar("onemore@mail.com"));
cc.add(new Scalar("another@email.com"));
m.put(CCS_ATTR, cc);
m.put(EMAIL_ATTR, "bad_email");
m.put(EMAIL_ATTR, "");
m.put(NAG_DISABLED_ATTR, NAG_DISABLED);

configurator.instance(m, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ public class EmailValidatorTest {

@Test
public void validEmails() {
assertTrue("simple email", EmailValidator.isValid("jdoe@acme.com"));
assertTrue("email with tag", EmailValidator.isValid("jdoe+advisor@acme.com"));
assertTrue("simple email", EmailValidator.isValidEmail("jdoe@acme.com"));
assertTrue("email with tag", EmailValidator.isValidEmail("jdoe+advisor@acme.com"));
assertTrue("JENKINS-65230 email", EmailValidator.isValidEmail("test.test-test@acme.com"));
// Not supported
//assertTrue("email with name", emailValidator.isValid("John Doe <jdoe@acme.com>"));
}

@Test
public void invalidEmails() {
assertFalse("email is empty", EmailValidator.isValid(""));
assertFalse("not an email", EmailValidator.isValid("Not valid"));
assertFalse("email with not root DN", EmailValidator.isValid("jdoe@acme"));
assertFalse("email is empty", EmailValidator.isValidEmail(""));
}

@Test
Expand All @@ -49,22 +48,6 @@ public void testDoCheckEmail() {
formValidation = EmailValidator.validateEmail(email + ",");
assertEquals(FormValidation.Kind.ERROR, formValidation.kind);

formValidation = EmailValidator.validateEmail("<Mr Foo> foo@acme.com");
assertEquals(FormValidation.Kind.ERROR, formValidation.kind);
formValidation = EmailValidator.validateEmail("Foo<foo@acme.com>");
assertEquals(FormValidation.Kind.ERROR, formValidation.kind);
formValidation = EmailValidator.validateEmail("Foo <foo@acme.com>");
assertEquals(FormValidation.Kind.ERROR, formValidation.kind);
formValidation = EmailValidator.validateEmail("\"foo\"@acme.com");
assertEquals(FormValidation.Kind.ERROR, formValidation.kind);
formValidation = EmailValidator.validateEmail("\"foo bar\"@acme.com");
assertEquals(FormValidation.Kind.ERROR, formValidation.kind);
formValidation = EmailValidator.validateEmail("\"foo\\ \"@acme.com");
assertEquals(FormValidation.Kind.ERROR, formValidation.kind);
formValidation = EmailValidator.validateEmail("\"foo\\ /\"@acme.com");
assertEquals(FormValidation.Kind.ERROR, formValidation.kind);


formValidation = EmailValidator.validateEmail(StringUtils.capitalize(email));
assertEquals(FormValidation.Kind.OK, formValidation.kind);
formValidation = EmailValidator.validateEmail(email);
Expand Down