You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ni...@apache.org on 2007/11/14 18:28:22 UTC

svn commit: r594961 - /commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java

Author: niallp
Date: Wed Nov 14 09:28:11 2007
New Revision: 594961

URL: http://svn.apache.org/viewvc?rev=594961&view=rev
Log:
Fix bug in UrlValidator (if ALLOW_ALL_SCHEMES option is on then MANUAL_AUTHORITY_VALIDATION has no effect) and make imutables variables final

Modified:
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java

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=594961&r1=594960&r2=594961&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 Wed Nov 14 09:28:11 2007
@@ -18,6 +18,7 @@
 
 import java.io.Serializable;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.regex.Matcher;
@@ -164,18 +165,18 @@
     /**
      * The set of schemes that are allowed to be in a URL.
      */
-    private Set allowedSchemes = new HashSet();
+    private final Set allowedSchemes;
 
     /**
      * Regular expressions used to manually validate authorities if IANA
      * domain name validation isn't desired.
      */
-    private RegexValidator[] authorityValidators;
+    private final RegexValidator[] authorityValidators;
 
     /**
      * If no schemes are provided, default to this set.
      */
-    protected String[] defaultSchemes = {"http", "https", "ftp"};
+    private static final String[] DEFAULT_SCHEMES = {"http", "https", "ftp"};
 
     /**
      * Singleton instance of this class with default schemes and options.
@@ -256,18 +257,21 @@
         this.options = options;
 
         if (isOn(ALLOW_ALL_SCHEMES)) {
-            return;
-        }
-
-        if (schemes == null) {
-            schemes = this.defaultSchemes;
+            this.allowedSchemes = Collections.EMPTY_SET;
+        } else {
+            if (schemes == null) {
+                schemes = DEFAULT_SCHEMES;
+            }
+            this.allowedSchemes = new HashSet();
+            this.allowedSchemes.addAll(Arrays.asList(schemes));
         }
 
         if (isOn(MANUAL_AUTHORITY_VALIDATION)) {
             this.authorityValidators = authorityValidators;
+        } else {
+            this.authorityValidators = null;
         }
 
-        this.allowedSchemes.addAll(Arrays.asList(schemes));
     }
 
     /**