[hibernate-issues] [Hibernate-JIRA] Created: (HV-591) EmailValidator throws an IllegalArgumentException for long email addresses

Marco Ramirez (JIRA) noreply at atlassian.com
Thu May 17 15:06:10 EDT 2012


EmailValidator throws an IllegalArgumentException for long email addresses
--------------------------------------------------------------------------

                 Key: HV-591
                 URL: https://hibernate.onjira.com/browse/HV-591
             Project: Hibernate Validator
          Issue Type: Bug
          Components: validators
    Affects Versions: 4.3.0.Final, 5.x
            Reporter: Marco Ramirez


When I attempt to validate the email address below the IDN.toASCII call throws an exception because it's using the entire email address and not just the domain.

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa at hibernate.org

In EmailValidator.java:

	public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
		if ( value == null || value.length() == 0 ) {
			return true;
		}
		String asciiString = IDN.toASCII( value.toString() ); //<- fails here
		Matcher m = pattern.matcher( asciiString );
		return m.matches();
	}

A test:

    @Test
    public void testForLongEmailAddresses(){
        final String longEmail = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa at hibernate.org";
        IllegalArgumentException e = null;
        try{
            new EmailValidator().isValid(longEmail, null);
        }catch (IllegalArgumentException f){
            e = f;
        }

        assertTrue(e == null, "IllegalArgumentException thrown while validating email address");
    }

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list