Path: blob/master/test/jdk/java/net/IDN/UseSTD3ASCIIRules.java
41149 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 802388126* @summary IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode27* in IDN.toASCII28*/2930import java.net.*;3132public class UseSTD3ASCIIRules {3334public static void main(String[] args) throws Exception {35// Per Section 4.1, RFC 3490, if the UseSTD3ASCIIRules flag is set,36// then perform these checks:37//38// (a) Verify the absence of non-LDH ASCII code points; that is, the39// absence of 0..2C, 2E..2F, 3A..40, 5B..60, and 7B..7F.40//41// (b) Verify the absence of leading and trailing hyphen-minus; that42// is, the absence of U+002D at the beginning and end of the43// sequence.44String[] illegalNames = {45"www.example.com-",46"-www.example.com",47"-www.example.com-",48"www.ex\u002Cmple.com",49"www.ex\u007Bmple.com",50"www.ex\u007Fmple.com"51};5253String[] legalNames = {54"www.ex-ample.com",55"www.ex\u002Dmple.com", // www.ex-mple.com56"www.ex\u007Ample.com", // www.exzmple.com57"www.ex\u3042mple.com", // www.xn--exmple-j43e.com58"www.\u3042\u3044\u3046.com", // www.xn--l8jeg.com59"www.\u793A\u4F8B.com" // www.xn--fsq092h.com60};6162for (String name : illegalNames) {63try {64System.out.println("Convering illegal IDN: " + name);65IDN.toASCII(name, IDN.USE_STD3_ASCII_RULES);66throw new Exception(67"Expected to get IllegalArgumentException for " + name);68} catch (IllegalArgumentException iae) {69// That's the right behavior.70}71}7273for (String name : legalNames) {74System.out.println("Convering legal IDN: " + name);75System.out.println("\tThe ACE form is: " +76IDN.toASCII(name, IDN.USE_STD3_ASCII_RULES));77}78}79}808182