commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bspeak...@apache.org
Subject svn commit: r589930 - 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 Tue, 30 Oct 2007 01:39:56 GMT
Author: bspeakmon
Date: Mon Oct 29 18:39:55 2007
New Revision: 589930

URL: http://svn.apache.org/viewvc?rev=589930&view=rev
Log:
- fix one-letter domain labels not validating
- fix handling of dashes

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=589930&r1=589929&r2=589930&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
Mon Oct 29 18:39:55 2007
@@ -63,7 +63,7 @@
 public class DomainValidator implements Serializable {
 
     // Regular expression strings for hostnames (derived from RFC2396 and RFC 1123)
-    private static final String DOMAIN_LABEL_REGEX = "\\p{Alnum}[\\p{Alnum}-]*\\p{Alnum}";
+    private static final String DOMAIN_LABEL_REGEX = "\\p{Alnum}(?:[\\p{Alnum}-]*\\p{Alnum})*";
     private static final String TOP_LABEL_REGEX = "\\p{Alpha}{2,}";
     private static final String DOMAIN_NAME_REGEX =
             "^(?:" + DOMAIN_LABEL_REGEX + "\\.)+" + "(" + TOP_LABEL_REGEX + ")$";

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=589930&r1=589929&r2=589930&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
Mon Oct 29 18:39:55 2007
@@ -36,9 +36,15 @@
         assertTrue("www.google.com should validate", validator.isValid("www.google.com"));
 
         assertTrue("test-domain.com should validate", validator.isValid("test-domain.com"));
+        assertTrue("test---domain.com should validate", validator.isValid("test---domain.com"));
+        assertTrue("test-d-o-m-ain.com should validate", validator.isValid("test-d-o-m-ain.com"));
         assertTrue("two-letter domain label should validate", validator.isValid("as.uk"));
 
         assertTrue("case-insensitive ApAchE.Org should validate", validator.isValid("ApAchE.Org"));
+
+        assertTrue("single-character domain label should validate", validator.isValid("z.com"));
+
+        assertTrue("i.have.an-example.domain.name should validate", validator.isValid("i.have.an-example.domain.name"));
     }
 
     public void testInvalidDomains() {
@@ -46,6 +52,9 @@
         assertFalse("domain name with spaces shouldn't validate", validator.isValid(" apache.org
"));
         assertFalse("domain name containing spaces shouldn't validate", validator.isValid("apa
che.org"));
         assertFalse("domain name starting with dash shouldn't validate", validator.isValid("-testdomain.name"));
+        assertFalse("domain name ending with dash shouldn't validate", validator.isValid("testdomain-.name"));
+        assertFalse("domain name starting with multiple dashes shouldn't validate", validator.isValid("---c.com"));
+        assertFalse("domain name ending with multiple dashes shouldn't validate", validator.isValid("c--.com"));
         assertFalse("domain name with invalid TLD shouldn't validate", validator.isValid("apache.rog"));
 
         assertFalse("URL shouldn't validate", validator.isValid("http://www.apache.org"));



Mime
View raw message