Skip to content

Commit 44cd815

Browse files
committed
HV-2057 Sonar: Update domain name regex
1 parent a8093f0 commit 44cd815

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

engine/src/main/java/org/hibernate/validator/internal/util/DomainNameUtil.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public final class DomainNameUtil {
2323
private static final int MAX_DOMAIN_PART_LENGTH = 255;
2424

2525
private static final String DOMAIN_CHARS_WITHOUT_DASH = "[a-z\u0080-\uFFFF0-9!#$%&'*+/=?^_`{|}~]";
26-
private static final String DOMAIN_LABEL = "(?:" + DOMAIN_CHARS_WITHOUT_DASH + "-*)*" + DOMAIN_CHARS_WITHOUT_DASH + "+";
27-
private static final String DOMAIN = DOMAIN_LABEL + "+(?:\\." + DOMAIN_LABEL + "+)*";
26+
private static final String DOMAIN_LABEL = DOMAIN_CHARS_WITHOUT_DASH + "++(?:-++" + DOMAIN_CHARS_WITHOUT_DASH + "++)*+";
27+
private static final String DOMAIN = DOMAIN_LABEL + "(?:\\." + DOMAIN_LABEL + ")*+";
2828

2929
private static final String IP_DOMAIN = "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}";
3030
//IP v6 regex taken from http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
@@ -92,11 +92,7 @@ private static boolean isValidDomainAddress(String domain, Pattern pattern) {
9292
}
9393

9494
Matcher matcher = pattern.matcher( domain );
95-
if ( !matcher.matches() ) {
96-
return false;
97-
}
98-
99-
return true;
95+
return matcher.matches();
10096
}
10197

10298
}

0 commit comments

Comments
 (0)