You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2020/07/26 17:05:14 UTC

[commons-validator] branch master updated: VALIDATOR-452 IPv4-mapped IPv6 address

This is an automated email from the ASF dual-hosted git repository.

sebb 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 1f2e113  VALIDATOR-452 IPv4-mapped IPv6 address
1f2e113 is described below

commit 1f2e113e90b20de2c6b8efe6f52a33e78dfcdce0
Author: Sebb <se...@apache.org>
AuthorDate: Sun Jul 26 18:05:05 2020 +0100

    VALIDATOR-452 IPv4-mapped IPv6 address
---
 src/changes/changes.xml                                              | 3 +++
 .../java/org/apache/commons/validator/routines/UrlValidator.java     | 3 ++-
 .../java/org/apache/commons/validator/routines/UrlValidatorTest.java | 5 +++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a136ba9..0efbbb7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -99,6 +99,9 @@ Apache Commons Validator.
 For the current list of dependencies, please see
 http://commons.apache.org/validator/dependencies.html
   ">
+    <action issue="VALIDATOR-452" type="fix" dev="sebb">
+    Validation of URL containing IPv4-mapped IPv6 address
+    </action>
     <action issue="VALIDATOR-471" type="add" dev="sebb">
     Allow DomainValidator overrides at run-time
     </action>
diff --git a/src/main/java/org/apache/commons/validator/routines/UrlValidator.java b/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
index f28be2d..29baa47 100644
--- a/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
+++ b/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
@@ -138,7 +138,8 @@ public class UrlValidator implements Serializable {
     // TODO does not allow for optional userinfo. 
     // Validation of character set is done by isValidAuthority
     private static final String AUTHORITY_CHARS_REGEX = "\\p{Alnum}\\-\\."; // allows for IPV4 but not IPV6
-    private static final String IPV6_REGEX = "[0-9a-fA-F:]+"; // do this as separate match because : could cause ambiguity with port prefix
+    // Allow for IPv4 mapped addresses: ::FFF:123.123.123.123
+    private static final String IPV6_REGEX = "::FFFF:(?:\\d{1,3}\\.){3}\\d{1,3}|[0-9a-fA-F:]+"; // do this as separate match because : could cause ambiguity with port prefix
 
     // userinfo    = *( unreserved / pct-encoded / sub-delims / ":" )
     // unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
diff --git a/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
index 130c902..c67926d 100644
--- a/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
@@ -339,6 +339,11 @@ public class UrlValidatorTest extends TestCase {
         assertFalse(fileNAK, urlValidator.isValid(fileNAK));
     }
 
+    public void testValidator452(){
+      UrlValidator urlValidator = new UrlValidator();
+      assertTrue(urlValidator.isValid("http://[::FFFF:129.144.52.38]:80/index.html"));
+    }
+
     static boolean incrementTestPartsIndex(int[] testPartsIndex, Object[] testParts) {
       boolean carry = true;  //add 1 to lowest order part.
       boolean maxIndex = true;