commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1649927 - in /commons/proper/validator/trunk/src: main/java/org/apache/commons/validator/routines/EmailValidator.java test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
Date Tue, 06 Jan 2015 20:15:09 GMT
Author: sebb
Date: Tue Jan  6 20:15:09 2015
New Revision: 1649927

URL: http://svn.apache.org/r1649927
Log:
VALIDATOR-235 UrlValidator rejects url with Unicode characters in domain label or TLD
Allow IDN domains for EmailValidator

Modified:
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java?rev=1649927&r1=1649926&r2=1649927&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java
Tue Jan  6 20:15:09 2015
@@ -42,12 +42,10 @@ public class EmailValidator implements S
     private static final String QUOTED_USER = "(\"[^\"]*\")";
     private static final String WORD = "((" + VALID_CHARS + "|')+|" + QUOTED_USER + ")";
 
-    private static final String LEGAL_ASCII_REGEX = "^\\p{ASCII}+$";
     private static final String EMAIL_REGEX = "^\\s*?(.+)@(.+?)\\s*$";
     private static final String IP_DOMAIN_REGEX = "^\\[(.*)\\]$";
     private static final String USER_REGEX = "^\\s*" + WORD + "(\\." + WORD + ")*$";
 
-    private static final Pattern MATCH_ASCII_PATTERN = Pattern.compile(LEGAL_ASCII_REGEX);
     private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX);
     private static final Pattern IP_DOMAIN_PATTERN = Pattern.compile(IP_DOMAIN_REGEX);
     private static final Pattern USER_PATTERN = Pattern.compile(USER_REGEX);
@@ -111,8 +109,7 @@ public class EmailValidator implements S
             return false;
         }
 
-        Matcher asciiMatcher = MATCH_ASCII_PATTERN.matcher(email);
-        if (!asciiMatcher.matches()) {
+        if (email.endsWith(".")) { // check this first - it's cheap!
             return false;
         }
 
@@ -122,10 +119,6 @@ public class EmailValidator implements S
             return false;
         }
 
-        if (email.endsWith(".")) {
-            return false;
-        }
-
         if (!isValidUser(emailMatcher.group(1))) {
             return false;
         }
@@ -140,7 +133,7 @@ public class EmailValidator implements S
     /**
      * Returns true if the domain component of an email address is valid.
      *
-     * @param domain being validated.
+     * @param domain being validated, may be in IDN format
      * @return true if the email address's domain is valid.
      */
     protected boolean isValidDomain(String domain) {

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java?rev=1649927&r1=1649926&r2=1649927&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
(original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
Tue Jan  6 20:15:09 2015
@@ -146,6 +146,20 @@ public class EmailValidatorTest extends
         assertFalse(validator.isValid("someone@test-.com"));// hostname ends with dash/hyphen
     }
 
+    public void testValidator235() {
+        String version = System.getProperty("java.version");
+        if (version.compareTo("1.6") < 0) {
+            System.out.println("Cannot run Unicode IDN tests");
+            return; // Cannot run the test
+        }
+        assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("someone@xn--d1abbgf6aiiy.xn--p1ai"));
+        assertTrue("президент.рф should validate", validator.isValid("someone@президент.рф"));
+        assertTrue("www.b\u00fccher.ch should validate", validator.isValid("someone@www.b\u00fccher.ch"));
+        assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("someone@www.\uFFFD.ch"));
+        assertTrue("www.b\u00fccher.ch should validate", validator.isValid("someone@www.b\u00fccher.ch"));
+        assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("someone@www.\uFFFD.ch"));
+    }
+
     /**
     * Tests the email validation with commas.
     */



Mime
View raw message