egulias / EmailValidator4J

Java RFC strict EmailValidator
MIT License
25 stars 8 forks source link

EmailValidator cannot be reused #6

Open liamjones opened 6 years ago

liamjones commented 6 years ago

Currently, EmailValidator4J's Parsers maintain internal state related to Warnings. The Parsers are instantiated at Validator construction time and then reused.

As such, as soon as a Warning is in a Parser the EmailValidator will incorrectly give that Warning back for any subsequent address checked.

Test case:

@Test
public void validatorCanBeReused() {
    EmailValidator validator = new EmailValidator();
    validator.isValid("test@[127.0.0.0]");
    Assert.assertFalse(validator.getWarnings().isEmpty());
    validator.isValid("test@example.com");
    Assert.assertFalse(validator.hasWarnings()); // Fails due to previous Warning still being present
}