Skip to content

Commit

Permalink
Query strings once
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Sep 19, 2024
1 parent 4955aa6 commit c5e6970
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,19 @@ public boolean isValidInet6Address(String inet6Address) {
if (containsCompressedZeroes && inet6Address.indexOf("::") != inet6Address.lastIndexOf("::")) {
return false;
}
if (inet6Address.startsWith(":") && !inet6Address.startsWith("::") || inet6Address.endsWith(":") && !inet6Address.endsWith("::")) {
final boolean startsWithCompressed = inet6Address.startsWith("::");
final boolean endsWithCompressed = inet6Address.endsWith("::");
final boolean endsWithSep = inet6Address.endsWith(":");
if (inet6Address.startsWith(":") && !startsWithCompressed || endsWithSep && !endsWithCompressed) {
return false;
}
String[] octets = inet6Address.split(":");
if (containsCompressedZeroes) {
final List<String> octetList = new ArrayList<>(Arrays.asList(octets));
if (inet6Address.endsWith("::")) {
if (endsWithCompressed) {
// String.split() drops ending empty segments
octetList.add("");
} else if (inet6Address.startsWith("::") && !octetList.isEmpty()) {
} else if (startsWithCompressed && !octetList.isEmpty()) {
octetList.remove(0);
}
octets = octetList.toArray(new String[0]);
Expand Down

0 comments on commit c5e6970

Please sign in to comment.