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/06/19 21:08:08 UTC

[commons-validator] branch master updated: VALIDATOR-467 - URL fails for //path_underscore

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 e9bda17  VALIDATOR-467 - URL fails for //path_underscore
e9bda17 is described below

commit e9bda17e9a27e4e8d1b951854baf838f0075619f
Author: Sebb <se...@apache.org>
AuthorDate: Fri Jun 19 22:07:58 2020 +0100

    VALIDATOR-467 - URL fails for //path_underscore
---
 src/changes/changes.xml                                          | 5 ++++-
 .../java/org/apache/commons/validator/routines/UrlValidator.java | 3 ++-
 .../org/apache/commons/validator/routines/UrlValidatorTest.java  | 9 ++++++++-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 89917cc..29a73c2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -128,7 +128,7 @@ http://commons.apache.org/validator/dependencies.html
     <action issue="VALIDATOR-461" type="fix" dev="sebb">
     Generic .gmbh top level domain is considered invalid
     </action>
-    <action issue="VALIDATOR-444" type="fix" dev="sebb">
+    <action issue="VALIDATOR-444" type="fix" dev="sebb" due=to="Marin Scholz">
     LongValidator: numbers bigger than the maxvalue are Valid
     </action>
     <action issue="VALIDATOR-416" type="fix" dev="sebb">
@@ -137,6 +137,9 @@ http://commons.apache.org/validator/dependencies.html
     <action issue="VALIDATOR-446" type="add" dev="sebb" due-to="Alex">
     ISSN Validator extract ISSN from EAN-13
     </action>
+    <action issue="VALIDATOR-467" type="fix" dev="sebb" due-to="Ivan Larionov">
+    URL validator fails if path starts with double slash and has underscores
+    </action>
   </release>
 
   <release version="1.6" date="2017-02-21" description="
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 312c8e8..8860a14 100644
--- a/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
+++ b/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
@@ -450,7 +450,8 @@ public class UrlValidator implements Serializable {
         }
 
         try {
-            URI uri = new URI(null,null,path,null);
+            // Don't omit host otherwise leading path may be taken as host if it starts with //
+            URI uri = new URI(null,"localhost",path,null);
             String norm = uri.normalize().getPath();
             if (norm.startsWith("/../") // Trying to go via the parent dir 
              || norm.equals("/..")) {   // Trying to go to the parent dir
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 9e48e07..7a40e3c 100644
--- a/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
@@ -498,7 +498,14 @@ protected void setUp() {
        assertTrue(validator.isValid("http://example.com/serach?address=Main+Avenue"));
    }
 
-   //-------------------- Test data for creating a composite URL
+   public void testValidator467() {
+      UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES);
+      assertTrue(validator.isValid("https://example.com/some_path/path/"));
+      assertTrue(validator.isValid("https://example.com//somepath/path/"));
+      assertTrue(validator.isValid("https://example.com//some_path/path/"));
+  }
+
+  //-------------------- Test data for creating a composite URL
    /**
     * The data given below approximates the 4 parts of a URL
     * <scheme>://<authority><path>?<query> except that the port number