Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CE41A10BB1 for ; Fri, 2 Jan 2015 19:13:04 +0000 (UTC) Received: (qmail 31971 invoked by uid 500); 2 Jan 2015 19:13:05 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 31910 invoked by uid 500); 2 Jan 2015 19:13:05 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 31900 invoked by uid 99); 2 Jan 2015 19:13:05 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Jan 2015 19:13:05 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id E3AAEAC08CB; Fri, 2 Jan 2015 19:13:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1649095 - /commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java Date: Fri, 02 Jan 2015 19:12:59 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150102191301.E3AAEAC08CB@hades.apache.org> Author: sebb Date: Fri Jan 2 19:12:59 2015 New Revision: 1649095 URL: http://svn.apache.org/r1649095 Log: Initial pass at handling XN-- TLD names Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java 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=1649095&r1=1649094&r2=1649095&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 Jan 2 19:12:59 2015 @@ -23,6 +23,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.HttpURLConnection; import java.net.URL; @@ -176,20 +177,36 @@ public class DomainValidatorTest extends System.out.println("Entries missing from TLD List\n"); String line; final String header; + final String version; line = br.readLine(); // header if (line.startsWith("# Version ")) { header = line.substring(2); System.out.println(" // Taken from " + header); + version = header.substring(0,header.indexOf(",")); } else { br.close(); throw new IOException("File does not have expected Version header"); } + final Method toUnicode = getIDNMethod(); + if (toUnicode == null) { + System.err.println("Cannot convert XN-- entries (no access to java.net.IDN)"); + } while((line = br.readLine()) != null) { - if (!line.startsWith("#") && !line.startsWith("XN--")) { - if (!dv.isValidTld(line)) { - System.out.println(" \""+line.toLowerCase(Locale.ENGLISH)+"\","); + if (!line.startsWith("#")) { + final String item; + if (line.startsWith("XN--")) { + if (toUnicode != null) { + item = toUnicode(toUnicode, line); + } else { + continue; + } + } else { + item = line.toLowerCase(Locale.ENGLISH); + } + if (!dv.isValidTld(item)) { + System.out.println(" \""+item+"\", // " + line + " added from " + version); } - ianaTlds.add(line.toLowerCase(Locale.ENGLISH)); + ianaTlds.add(item); } } br.close(); @@ -201,6 +218,23 @@ public class DomainValidatorTest extends // Don't check local TLDS isInIanaList("LOCAL_TLDS", ianaTlds); } + private static String toUnicode(Method m, String line) { + try { + return (String) m.invoke(null, new String[]{line.toLowerCase(Locale.ENGLISH)}); + } catch (Exception e) { + } + return line; + } + + private static Method getIDNMethod() { + try { + Class clazz = Class.forName("java.net.IDN", false, DomainValidatorTest.class.getClassLoader()); + return clazz.getDeclaredMethod("toUnicode", new Class[]{String.class}); + } catch (Exception e) { + return null; + } + } + // isInIanaList and isSorted are split into two methods. // If/when access to the arrays is possible without reflection, the intermediate // methods can be dropped