Skip to content

Commit

Permalink
HV-1833 Check the regexp after the size when validating domain names
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Mar 8, 2021
1 parent b5d64de commit dd4eb35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ private static boolean isValidDomainAddress(String domain, Pattern pattern) {
return false;
}

Matcher matcher = pattern.matcher( domain );
if ( !matcher.matches() ) {
return false;
}

String asciiString;
try {
asciiString = IDN.toASCII( domain );
Expand All @@ -97,6 +92,11 @@ private static boolean isValidDomainAddress(String domain, Pattern pattern) {
return false;
}

Matcher matcher = pattern.matcher( domain );
if ( !matcher.matches() ) {
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import org.hibernate.validator.cfg.ConstraintMapping;
import org.hibernate.validator.cfg.defs.EmailDef;
import org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator;
import org.hibernate.validator.internal.util.DomainNameUtil;
import org.hibernate.validator.internal.util.StringHelper;
import org.hibernate.validator.testutil.MyCustomStringImpl;
import org.hibernate.validator.testutil.TestForIssue;
import org.hibernate.validator.testutils.ValidatorUtil;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -222,6 +222,12 @@ public void testEmailWith256CharacterDomainPartIsInvalid() {
isInvalidEmail( "foo@" + domainOfLength( 252 ) + ".com" );
}

@Test
@TestForIssue(jiraKey = "HV-1833")
public void testLongEmail() {
assertEquals( false, DomainNameUtil.isValidEmailDomainAddress( stringOfLength( 5000 ) + ".com" ) );
}

private String stringOfLength(int length) {
StringBuilder builder = new StringBuilder();
for ( int i = 0; i < length; i++ ) {
Expand Down

0 comments on commit dd4eb35

Please sign in to comment.