This is an automated email from the ASF dual-hosted git repository. chibenwa pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-jspf.git
commit 8820814afe95c3f647ebc265129ff52ff3703254 Author: Benoit TELLIER <[email protected]> AuthorDate: Tue Nov 10 18:03:24 2026 +0100 [FIX] Inet6Util: test an empty word with isEmpty(), not == The check held only because word was the "" literal: any other empty String would have reached Integer.parseInt or been accepted. Fixes https://github.com/linagora/james-jspf/issues/25 --- resolver/src/main/java/org/apache/james/jspf/core/Inet6Util.java | 6 +++--- .../src/test/java/org/apache/james/jspf/core/IPAddrTest.java | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/resolver/src/main/java/org/apache/james/jspf/core/Inet6Util.java b/resolver/src/main/java/org/apache/james/jspf/core/Inet6Util.java index e917c52..95853b8 100644 --- a/resolver/src/main/java/org/apache/james/jspf/core/Inet6Util.java +++ b/resolver/src/main/java/org/apache/james/jspf/core/Inet6Util.java @@ -357,7 +357,7 @@ public class Inet6Util { // a : or a . // If we did not end in :: then this is invalid if (numberOfPercent == 0) { - if (word == "" && ipAddress.charAt(length - 1 - offset) == ':' + if (word.isEmpty() && ipAddress.charAt(length - 1 - offset) == ':' && ipAddress.charAt(length - 2 - offset) != ':') { return false; } @@ -429,7 +429,7 @@ public class Inet6Util { periods++; if (periods > 3) return false; - if (word == "") + if (word.isEmpty()) return false; if (Integer.parseInt(word) > 255) return false; @@ -443,7 +443,7 @@ public class Inet6Util { } } - if (word == "" || Integer.parseInt(word) > 255) + if (word.isEmpty() || Integer.parseInt(word) > 255) return false; if (periods != 3) return false; diff --git a/resolver/src/test/java/org/apache/james/jspf/core/IPAddrTest.java b/resolver/src/test/java/org/apache/james/jspf/core/IPAddrTest.java index 3214eb9..7ce0199 100644 --- a/resolver/src/test/java/org/apache/james/jspf/core/IPAddrTest.java +++ b/resolver/src/test/java/org/apache/james/jspf/core/IPAddrTest.java @@ -152,4 +152,13 @@ public class IPAddrTest extends TestCase { } } + public void testEmptyWordsAreInvalid() { + assertFalse(Inet6Util.isValidIPV4Address("")); + assertFalse(Inet6Util.isValidIPV4Address("1..2.3")); + assertFalse(Inet6Util.isValidIPV4Address("1.2.3.")); + assertFalse(Inet6Util.isValidIPV4Address(".1.2.3")); + assertFalse(Inet6Util.isValidIP6Address("1:2:3:4:5:6:7:")); + assertTrue(Inet6Util.isValidIPV4Address("1.2.3.4")); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
