commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bspeak...@apache.org
Subject svn commit: r589273 - /commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java
Date Sun, 28 Oct 2007 06:09:49 GMT
Author: bspeakmon
Date: Sat Oct 27 23:09:48 2007
New Revision: 589273

URL: http://svn.apache.org/viewvc?rev=589273&view=rev
Log:
- VALIDATOR-191: incrementally replacing oro with java.util.regex

Modified:
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.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=589273&r1=589272&r2=589273&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
Sat Oct 27 23:09:48 2007
@@ -42,21 +42,20 @@
  */
 public class EmailValidator implements Serializable {
 
-    private static final String SPECIAL_CHARS = "\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177";
+    private static final String SPECIAL_CHARS = "\\p{Cntrl}\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]";
     private static final String VALID_CHARS = "[^\\s" + SPECIAL_CHARS + "]";
     private static final String QUOTED_USER = "(\"[^\"]*\")";
     private static final String ATOM = VALID_CHARS + '+';
     private static final String WORD = "((" + VALID_CHARS + "|')+|" + QUOTED_USER + ")";
 
-    // Each pattern must be surrounded by /
     private static final String LEGAL_ASCII_PATTERN = "^\\p{ASCII}+$";
     private static final String EMAIL_PATTERN = "^(.+)@(.+)$";
     private static final String IP_DOMAIN_PATTERN = "^\\[(.*)\\]$";
     private static final String TLD_PATTERN = "^\\p{Alpha}+$";
 
-    private static final String USER_PATTERN = "/^\\s*" + WORD + "(\\." + WORD + ")*$/";
-    private static final String DOMAIN_PATTERN = "/^" + ATOM + "(\\." + ATOM + ")*\\s*$/";
-    private static final String ATOM_PATTERN = "/(" + ATOM + ")/";
+    private static final String USER_PATTERN = "^\\s*" + WORD + "(\\." + WORD + ")*$";
+    private static final String DOMAIN_PATTERN = "^" + ATOM + "(\\." + ATOM + ")*\\s*$";
+    private static final String ATOM_PATTERN = "(" + ATOM + ")";
 
     /**
      * Singleton instance of this class.
@@ -96,8 +95,8 @@
             return false;
         }
 
-        email = stripComments(email);
 
+        
         // Check the whole email address structure
         Pattern emailPattern = Pattern.compile(EMAIL_PATTERN);
         Matcher emailMatcher = emailPattern.matcher(email);
@@ -140,8 +139,7 @@
             }
         } else {
             // Domain is symbolic name
-            Perl5Util domainMatcher = new Perl5Util();
-            symbolic = domainMatcher.match(DOMAIN_PATTERN, domain);
+            symbolic = Pattern.matches(DOMAIN_PATTERN, domain);
         }
 
         if (symbolic) {
@@ -161,8 +159,7 @@
      * @return true if the user name is valid.
      */
     protected boolean isValidUser(String user) {
-        Perl5Util userMatcher = new Perl5Util();
-        return userMatcher.match(USER_PATTERN, user);
+        return Pattern.matches(USER_PATTERN, user);
     }
 
     /**
@@ -174,17 +171,16 @@
         String[] domainSegment = new String[10];
         boolean match = true;
         int i = 0;
-        Perl5Util atomMatcher = new Perl5Util();
+
+        // Iterate through the domain, checking that it's composed
+        // of valid atoms in between the dots.
+        // FIXME: This should be cleaned up some more; it's still a bit dodgy.
+        Pattern atomPattern = Pattern.compile(ATOM_PATTERN);
+        Matcher atomMatcher = atomPattern.matcher(domain);
         while (match) {
-            match = atomMatcher.match(ATOM_PATTERN, domain);
+            match = atomMatcher.find();
             if (match) {
                 domainSegment[i] = atomMatcher.group(1);
-                int l = domainSegment[i].length() + 1;
-                domain =
-                        (l >= domain.length())
-                        ? ""
-                        : domain.substring(l);
-
                 i++;
             }
         }



Mime
View raw message