commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bspeak...@apache.org
Subject svn commit: r589976 - /commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
Date Tue, 30 Oct 2007 06:55:21 GMT
Author: bspeakmon
Date: Mon Oct 29 23:55:21 2007
New Revision: 589976

URL: http://svn.apache.org/viewvc?rev=589976&view=rev
Log:
- VALIDATOR-203: simplify isValidAuthority() and removing now-unused regexps
  since this class is no longer in the domain-validating business

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=589976&r1=589975&r2=589976&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 Oct 29 23:55:21 2007
@@ -93,17 +93,11 @@
 
     private static final String ALPHA_NUMERIC_CHARS = ALPHA_CHARS + "\\d";
 
-    private static final String SPECIAL_CHARS = ";/@&=,.?:+$";
-
-    private static final String VALID_CHARS = "[^\\s" + SPECIAL_CHARS + "]";
-
     private static final String SCHEME_CHARS = ALPHA_CHARS;
 
     // Drop numeric, and  "+-." for now
     private static final String AUTHORITY_CHARS = ALPHA_NUMERIC_CHARS + "\\-\\.";
 
-    private static final String ATOM = VALID_CHARS + '+';
-
     /**
      * This expression derived/taken from the BNF for URI (RFC2396).
      */
@@ -151,15 +145,8 @@
 
     private static final String LEGAL_ASCII_PATTERN = "/^[\\000-\\177]+$/";
 
-    private static final String DOMAIN_PATTERN =
-            "/^" + ATOM + "(\\." + ATOM + ")*$/";
-
     private static final String PORT_PATTERN = "/^:(\\d{1,5})$/";
 
-    private static final String ATOM_PATTERN = "/(" + ATOM + ")/";
-
-    private static final String ALPHA_PATTERN = "/^[" + ALPHA_CHARS + "]/";
-
     /**
      * Holds the set of current validation options.
      */
@@ -325,26 +312,22 @@
         }
 
         Perl5Util authorityMatcher = new Perl5Util();
-        InetAddressValidator inetAddressValidator =
-                InetAddressValidator.getInstance();
-
         if (!authorityMatcher.match(AUTHORITY_PATTERN, authority)) {
             return false;
         }
 
-        boolean hostname = false;
-        // check if authority is IP address or hostname
-        String hostIP = authorityMatcher.group(PARSE_AUTHORITY_HOST_IP);
-        boolean ipV4Address = inetAddressValidator.isValid(hostIP);
-
-        if (!ipV4Address) {
-            // Domain is hostname name
-            DomainValidator validator = DomainValidator.getInstance();
-            hostname = validator.isValid(hostIP);
-        }
-
-        if (!hostname && !ipV4Address) {
-            return false;
+        String hostLocation = authorityMatcher.group(PARSE_AUTHORITY_HOST_IP);
+        // check if authority is hostname or IP address:
+        // try a hostname first since that's much more likely
+        DomainValidator domainValidator = DomainValidator.getInstance();
+        if (!domainValidator.isValid(hostLocation)) {
+            // try an IP address
+            InetAddressValidator inetAddressValidator =
+                InetAddressValidator.getInstance();
+            if (!inetAddressValidator.isValid(hostLocation)) {
+                // isn't either one, so the URL is invalid
+                return false;
+            }
         }
 
         String port = authorityMatcher.group(PARSE_AUTHORITY_PORT);



Mime
View raw message