Uploaded image for project: 'Hibernate Validator'
  1. HV-591

EmailValidator throws an IllegalArgumentException for long email addresses

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      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, eg aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@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@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");
          }
      

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: