commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1713569 - in /commons/proper/validator/trunk/src: changes/changes.xml main/java/org/apache/commons/validator/routines/UrlValidator.java test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
Date Mon, 09 Nov 2015 23:39:18 GMT
Author: sebb
Date: Mon Nov  9 23:39:18 2015
New Revision: 1713569

URL: http://svn.apache.org/viewvc?rev=1713569&view=rev
Log:
VALIDATOR-380 UrlValidator does not allow for optional port digits

Modified:
    commons/proper/validator/trunk/src/changes/changes.xml
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java

Modified: commons/proper/validator/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/changes/changes.xml?rev=1713569&r1=1713568&r2=1713569&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/changes/changes.xml (original)
+++ commons/proper/validator/trunk/src/changes/changes.xml Mon Nov  9 23:39:18 2015
@@ -90,6 +90,9 @@ The dependencies for Validator have not
 For the current list of dependencies, please see
 http://commons.apache.org/validator/dependencies.html
   ">
+    <action issue="VALIDATOR-380" type="fix" dev="sebb">
+    UrlValidator does not allow for optional port digits
+    </action>
     <action issue="VALIDATOR-332" type="update" dev="sebb">
     IIBANCheckDigit.calculate does not enforce initial checksum value
     Checkdigit field is now unconditionally set to "00" to ensure correct generation

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java?rev=1713569&r1=1713568&r2=1713569&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
Mon Nov  9 23:39:18 2015
@@ -146,15 +146,16 @@ public class UrlValidator implements Ser
             USERINFO_CHARS_REGEX + "+:" + // At least one character for the name
             USERINFO_CHARS_REGEX + "*@"; // password may be absent
     private static final String AUTHORITY_REGEX =
-            "^(?:\\[("+IPV6_REGEX+")\\]|(?:(?:"+USERINFO_FIELD_REGEX+")?([" + AUTHORITY_CHARS_REGEX
+ "]*)))(:\\d*)?(.*)?";
-    //                   1                 e.g. user:pass@                         2    
                    3       4
+            "(?:\\[("+IPV6_REGEX+")\\]|(?:(?:"+USERINFO_FIELD_REGEX+")?([" + AUTHORITY_CHARS_REGEX
+ "]*)))(:\\d*)?(.*)?";
+    //             1                          e.g. user:pass@          2                
                  3       4
     private static final Pattern AUTHORITY_PATTERN = Pattern.compile(AUTHORITY_REGEX);
 
     private static final int PARSE_AUTHORITY_IPV6 = 1;
 
-    private static final int PARSE_AUTHORITY_HOST_IP = 2;
+    private static final int PARSE_AUTHORITY_HOST_IP = 2; // excludes userinfo, if present
 
-    private static final int PARSE_AUTHORITY_PORT = 3;
+    // Not needed, because it is validated by AUTHORITY_REGEX
+//    private static final int PARSE_AUTHORITY_PORT = 3;
 
     /**
      * Should always be empty. The code currently allows spaces.
@@ -167,9 +168,6 @@ public class UrlValidator implements Ser
     private static final String QUERY_REGEX = "^(.*)$";
     private static final Pattern QUERY_PATTERN = Pattern.compile(QUERY_REGEX);
 
-    private static final String PORT_REGEX = "^:(\\d{1,5})$";
-    private static final Pattern PORT_PATTERN = Pattern.compile(PORT_REGEX);
-
     /**
      * Holds the set of current validation options.
      */
@@ -311,9 +309,14 @@ public class UrlValidator implements Ser
         }
 
         String authority = urlMatcher.group(PARSE_URL_AUTHORITY);
-        if ("file".equals(scheme) && "".equals(authority)) {
-            // Special case - file: allows an empty authority
-        } else {
+        if ("file".equals(scheme)) {// Special case - file: allows an empty authority
+            if (!"".equals(authority)) {
+                if (authority.contains(":")) { // but cannot allow trailing :
+                    return false;
+                }
+            }
+            // drop through to continue validation
+        } else { // not file:
             // Validate the authority
             if (!isValidAuthority(authority)) {
                 return false;
@@ -410,11 +413,6 @@ public class UrlValidator implements Ser
             }
         }
 
-        String port = authorityMatcher.group(PARSE_AUTHORITY_PORT);
-        if (port != null && !PORT_PATTERN.matcher(port).matches()) {
-            return false;
-        }
-
         String extra = authorityMatcher.group(PARSE_AUTHORITY_EXTRA);
         if (extra != null && extra.trim().length() > 0){
             return false;

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java?rev=1713569&r1=1713568&r2=1713569&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
(original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
Mon Nov  9 23:39:18 2015
@@ -441,8 +441,7 @@ public class UrlValidatorTest extends Te
        UrlValidator validator = new UrlValidator();
        assertTrue(validator.isValid("http://www.apache.org:80/path"));       
        assertTrue(validator.isValid("http://www.apache.org:8/path")); 
-       // To be enabled when code has been fixed
-//       assertTrue(validator.isValid("http://www.apache.org:/path"));
+       assertTrue(validator.isValid("http://www.apache.org:/path"));
    }
 
    /**



Mime
View raw message