You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/09/19 12:53:26 UTC
(commons-validator) branch master updated: Query strings once
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-validator.git
The following commit(s) were added to refs/heads/master by this push:
new c5e69709 Query strings once
c5e69709 is described below
commit c5e69709c0c1a452585d79a48411e43ed415ac27
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Sep 19 08:53:19 2024 -0400
Query strings once
---
.../apache/commons/validator/routines/InetAddressValidator.java | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java b/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
index 07d90038..868c251d 100644
--- a/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
+++ b/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
@@ -159,16 +159,19 @@ public class InetAddressValidator implements Serializable {
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]);