Skip to content
New issue

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

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

Already on GitHub? # to your account

Update regexp pattern to safer one #12104

Merged
merged 3 commits into from
Sep 30, 2020
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 @@ -34,6 +34,12 @@
@SuppressWarnings("serial")
public class EmailValidator extends RegexpValidator {

private static final String PATTERN = "^" + "([a-zA-Z0-9_\\.\\-+])+" // local
+ "@" + "[a-zA-Z0-9-.]+" // domain
+ "\\." + "[a-zA-Z0-9-]{2,}" // tld
+ "$";


/**
* Creates a validator for checking that a string is a syntactically valid
* e-mail address.
Expand All @@ -42,7 +48,6 @@ public class EmailValidator extends RegexpValidator {
* the message to display in case the value does not validate.
*/
public EmailValidator(String errorMessage) {
super("^([a-zA-Z0-9_\\.\\-+])+@(([a-zA-Z0-9-])+\\.)+([a-zA-Z0-9]{2,4})+$",
true, errorMessage);
super(PATTERN, true, errorMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ public void testEmailValidatorWithFaultyString() {
public void testEmailValidatorWithOkEmail() {
Assert.assertTrue(validator.isValid("my.name@email.com"));
}

@Test
public void testEmailValidatorWithBadInput() {
Assert.assertFalse(validator.isValid("a@a.m5qRt8zLxQG4mMeu9yKZm5qRt8zLxQG4mMeu9yKZm5qRt8zLxQG4mMeu9yKZ&"));
}

}