commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1128395 - in /commons/proper/validator/trunk/src: main/java/org/apache/commons/validator/routines/DomainValidator.java test/java/org/apache/commons/validator/routines/DomainValidatorTest.java
Date Fri, 27 May 2011 17:03:51 GMT
Author: nick
Date: Fri May 27 17:03:51 2011
New Revision: 1128395

URL: http://svn.apache.org/viewvc?rev=1128395&view=rev
Log:
VALIDATOR-288 - Update DomainValidator to accept a machine name when local addresses are allowed

Modified:
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java?rev=1128395&r1=1128394&r2=1128395&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
Fri May 27 17:03:51 2011
@@ -87,6 +87,11 @@ public class DomainValidator implements 
      */
     private final RegexValidator domainRegex =
             new RegexValidator(DOMAIN_NAME_REGEX);
+    /**
+     * RegexValidator for matching the a local hostname
+     */
+    private final RegexValidator hostnameRegex =
+            new RegexValidator(DOMAIN_LABEL_REGEX);
 
     /**
      * Returns the singleton instance of this validator. It
@@ -126,7 +131,7 @@ public class DomainValidator implements 
         if (groups != null && groups.length > 0) {
             return isValidTld(groups[0]);
         } else if(allowLocal) {
-            if ("localhost".equals(domain)) {
+            if (hostnameRegex.isValid(domain)) {
                return true;
             }
         }

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java?rev=1128395&r1=1128394&r2=1128395&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java
(original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java
Fri May 27 17:03:51 2011
@@ -99,6 +99,8 @@ public class DomainValidatorTest extends
        // But it may be requested
        assertTrue("localhost.localdomain should validate", allowLocal.isValid("localhost.localdomain"));
        assertTrue("localhost should validate", allowLocal.isValid("localhost"));
+       assertTrue("hostname should validate", allowLocal.isValid("hostname"));
+       assertTrue("machinename should validate", allowLocal.isValid("machinename"));
        
        // Check the localhost one with a few others
        assertTrue("apache.org should validate", allowLocal.isValid("apache.org"));



Mime
View raw message