commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1651525 - /commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
Date Tue, 13 Jan 2015 22:30:28 GMT
Author: sebb
Date: Tue Jan 13 22:30:28 2015
New Revision: 1651525

URL: http://svn.apache.org/r1651525
Log:
Add temporary hack to get round IDN.toASCII bug
It is not supposed to change ASCII input but it converts trailing ".." to "."

Modified:
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.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=1651525&r1=1651524&r2=1651525&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
Tue Jan 13 22:30:28 2015
@@ -1085,6 +1085,9 @@ public class DomainValidator implements
      */
     // Needed by UrlValidator
     static String unicodeToASCII(String input) {
+        if (isOnlyASCII(input)) { // TODO temporary hack to work round IDN.toASCII bug
+            return input;
+        }
         try {
             return IDN.toASCII(input);
         } catch (IllegalArgumentException e) { // input is not valid
@@ -1092,4 +1095,19 @@ public class DomainValidator implements
         }
     }
 
+    /*
+     * Check if input contains only ASCII
+     * Treats null as all ASCII
+     */
+    private static boolean isOnlyASCII(String input) {
+        if (input == null) {
+            return true;
+        }
+        for(int i=0; i < input.length(); i++) {
+            if (input.charAt(i) > 0x7F) {
+                return false;
+            }
+        }
+        return true;
+    }
 }



Mime
View raw message