commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1713488 - in /commons/proper/validator/trunk/src: changes/changes.xml main/java/org/apache/commons/validator/routines/UrlValidator.java site/xdoc/download_validator.xml test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
Date Fri, 02 Dec 2016 03:11:42 GMT
Author: sebb
Date: Mon Nov  9 17:48:28 2015
New Revision: 1713488

URL: http://svn.apache.org/viewvc?rev=1713488&view=rev
Log:
VALIDATOR-353 UrlValidator does not allow for optional userinfo in the authority

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/site/xdoc/download_validator.xml
    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=1713488&r1=1713487&r2=1713488&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/changes/changes.xml (original)
+++ commons/proper/validator/trunk/src/changes/changes.xml Mon Nov  9 17:48:28 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-353" type="update" dev="sebb">
+    UrlValidator does not allow for optional userinfo in the authority
+    </action>
     <action issue="VALIDATOR-321" type="add" dev="sebb">
     ISSN validator and converter to EAN-13
     </action>

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=1713488&r1=1713487&r2=1713488&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 17:48:28 2015
@@ -136,9 +136,18 @@ public class UrlValidator implements Ser
     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
 
+    // userinfo    = *( unreserved / pct-encoded / sub-delims / ":" )
+    // unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
+    // sub-delims    = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
+    // We assume that password has the same valid chars as user info
+    private static final String USERINFO_CHARS_REGEX = "[a-zA-Z0-9%-._~!$&'()*+,;=]";
+    // since neither ':' nor '@' are allowed chars, we don't need to use non-greedy matching
+    private static final String USERINFO_FIELD_REGEX =
+            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+")\\]|([" + AUTHORITY_CHARS_REGEX + "]*))(:\\d*)?(.*)?";
-    //                   1                              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;

Modified: commons/proper/validator/trunk/src/site/xdoc/download_validator.xml
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/site/xdoc/download_validator.xml?rev=1713488&r1=1713487&r2=1713488&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/site/xdoc/download_validator.xml (original)
+++ commons/proper/validator/trunk/src/site/xdoc/download_validator.xml Mon Nov  9 17:48:28
2015
@@ -95,62 +95,62 @@ limitations under the License.
       </p>
     </subsection>
     </section>
-    <section name="Apache Commons Validator 1.4.1 (requires JDK 1.4)">
+    <section name="Apache Commons Validator 1.5.0 (requires JDK 1.6)">
       <subsection name="Binaries">
         <table>
           <tr>
-              <td><a href="[preferred]/commons/validator/binaries/commons-validator-1.4.1-bin.tar.gz">commons-validator-1.4.1-bin.tar.gz</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.4.1-bin.tar.gz.md5">md5</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.4.1-bin.tar.gz.asc">pgp</a></td>
+              <td><a href="[preferred]/commons/validator/binaries/commons-validator-1.5.0-bin.tar.gz">commons-validator-1.5.0-bin.tar.gz</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.5.0-bin.tar.gz.md5">md5</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.5.0-bin.tar.gz.asc">pgp</a></td>
           </tr>
           <tr>
-              <td><a href="[preferred]/commons/validator/binaries/commons-validator-1.4.1-bin.zip">commons-validator-1.4.1-bin.zip</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.4.1-bin.zip.md5">md5</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.4.1-bin.zip.asc">pgp</a></td>
+              <td><a href="[preferred]/commons/validator/binaries/commons-validator-1.5.0-bin.zip">commons-validator-1.5.0-bin.zip</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.5.0-bin.zip.md5">md5</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.5.0-bin.zip.asc">pgp</a></td>
           </tr>
         </table>
       </subsection>
       <subsection name="Source">
         <table>
           <tr>
-              <td><a href="[preferred]/commons/validator/source/commons-validator-1.4.1-src.tar.gz">commons-validator-1.4.1-src.tar.gz</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.4.1-src.tar.gz.md5">md5</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.4.1-src.tar.gz.asc">pgp</a></td>
+              <td><a href="[preferred]/commons/validator/source/commons-validator-1.5.0-src.tar.gz">commons-validator-1.5.0-src.tar.gz</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.5.0-src.tar.gz.md5">md5</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.5.0-src.tar.gz.asc">pgp</a></td>
           </tr>
           <tr>
-              <td><a href="[preferred]/commons/validator/source/commons-validator-1.4.1-src.zip">commons-validator-1.4.1-src.zip</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.4.1-src.zip.md5">md5</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.4.1-src.zip.asc">pgp</a></td>
+              <td><a href="[preferred]/commons/validator/source/commons-validator-1.5.0-src.zip">commons-validator-1.5.0-src.zip</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.5.0-src.zip.md5">md5</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.5.0-src.zip.asc">pgp</a></td>
           </tr>
         </table>
       </subsection>
     </section>
-    <section name="Apache Commons Validator 1.3.1 (requires JDK 1.3)">
+    <section name="Apache Commons Validator 1.4.1 (requires JDK 1.4)">
       <subsection name="Binaries">
         <table>
           <tr>
-              <td><a href="[preferred]/commons/validator/binaries/commons-validator-1.3.1.tar.gz">commons-validator-1.3.1.tar.gz</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.3.1.tar.gz.md5">md5</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.3.1.tar.gz.asc">pgp</a></td>
+              <td><a href="[preferred]/commons/validator/binaries/commons-validator-1.4.1.tar.gz">commons-validator-1.4.1.tar.gz</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.4.1.tar.gz.md5">md5</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.4.1.tar.gz.asc">pgp</a></td>
           </tr>
           <tr>
-              <td><a href="[preferred]/commons/validator/binaries/commons-validator-1.3.1.zip">commons-validator-1.3.1.zip</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.3.1.zip.md5">md5</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.3.1.zip.asc">pgp</a></td>
+              <td><a href="[preferred]/commons/validator/binaries/commons-validator-1.4.1.zip">commons-validator-1.4.1.zip</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.4.1.zip.md5">md5</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/binaries/commons-validator-1.4.1.zip.asc">pgp</a></td>
           </tr>
         </table>
       </subsection>
       <subsection name="Source">
         <table>
           <tr>
-              <td><a href="[preferred]/commons/validator/source/commons-validator-1.3.1-src.tar.gz">commons-validator-1.3.1-src.tar.gz</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.3.1-src.tar.gz.md5">md5</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.3.1-src.tar.gz.asc">pgp</a></td>
+              <td><a href="[preferred]/commons/validator/source/commons-validator-1.4.1-src.tar.gz">commons-validator-1.4.1-src.tar.gz</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.4.1-src.tar.gz.md5">md5</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.4.1-src.tar.gz.asc">pgp</a></td>
           </tr>
           <tr>
-              <td><a href="[preferred]/commons/validator/source/commons-validator-1.3.1-src.zip">commons-validator-1.3.1-src.zip</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.3.1-src.zip.md5">md5</a></td>
-              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.3.1-src.zip.asc">pgp</a></td>
+              <td><a href="[preferred]/commons/validator/source/commons-validator-1.4.1-src.zip">commons-validator-1.4.1-src.zip</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.4.1-src.zip.md5">md5</a></td>
+              <td><a href="http://www.apache.org/dist/commons/validator/source/commons-validator-1.4.1-src.zip.asc">pgp</a></td>
           </tr>
         </table>
       </subsection>

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=1713488&r1=1713487&r2=1713488&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 17:48:28 2015
@@ -16,10 +16,10 @@
  */
 package org.apache.commons.validator.routines;
 
-import junit.framework.TestCase;
-
 import org.apache.commons.validator.ResultPair;
 
+import junit.framework.TestCase;
+
 /**
  * Performs Validation Test for url validations.
  *
@@ -424,7 +424,19 @@ public class UrlValidatorTest extends Te
        assertFalse("IPv6 address without [] should not validate: " + url, validator.isValid(url));
     }
 
-   
+
+   public void testValidator353() { // userinfo
+       UrlValidator validator = new UrlValidator();
+       assertTrue(validator.isValid("http://www.apache.org:80/path"));
+       assertTrue(validator.isValid("http://user:pass@www.apache.org:80/path"));
+       assertTrue(validator.isValid("http://user:@www.apache.org:80/path"));
+       assertTrue(validator.isValid("http://us%00er:-._~!$&'()*+,;=@www.apache.org:80/path"));
+       assertFalse(validator.isValid("http://:pass@www.apache.org:80/path"));
+       assertFalse(validator.isValid("http://:@www.apache.org:80/path"));
+       assertFalse(validator.isValid("http://user:pa:ss@www.apache.org/path"));
+       assertFalse(validator.isValid("http://user:pa@ss@www.apache.org/path"));
+   }
+
    /**
     * Only used to debug the unit tests.
     * @param argv



Mime
View raw message