Skip to content

Commit

Permalink
HV-2057 Sonar: Update domain name regex
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Oct 24, 2024
1 parent a8093f0 commit 44cd815
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public final class DomainNameUtil {
private static final int MAX_DOMAIN_PART_LENGTH = 255;

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

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

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

return true;
return matcher.matches();
}

}

0 comments on commit 44cd815

Please sign in to comment.