Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/IDN/UseSTD3ASCIIRules.java
41149 views
1
/*
2
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8023881
27
* @summary IDN.USE_STD3_ASCII_RULES option is too strict to use Unicode
28
* in IDN.toASCII
29
*/
30
31
import java.net.*;
32
33
public class UseSTD3ASCIIRules {
34
35
public static void main(String[] args) throws Exception {
36
// Per Section 4.1, RFC 3490, if the UseSTD3ASCIIRules flag is set,
37
// then perform these checks:
38
//
39
// (a) Verify the absence of non-LDH ASCII code points; that is, the
40
// absence of 0..2C, 2E..2F, 3A..40, 5B..60, and 7B..7F.
41
//
42
// (b) Verify the absence of leading and trailing hyphen-minus; that
43
// is, the absence of U+002D at the beginning and end of the
44
// sequence.
45
String[] illegalNames = {
46
"www.example.com-",
47
"-www.example.com",
48
"-www.example.com-",
49
"www.ex\u002Cmple.com",
50
"www.ex\u007Bmple.com",
51
"www.ex\u007Fmple.com"
52
};
53
54
String[] legalNames = {
55
"www.ex-ample.com",
56
"www.ex\u002Dmple.com", // www.ex-mple.com
57
"www.ex\u007Ample.com", // www.exzmple.com
58
"www.ex\u3042mple.com", // www.xn--exmple-j43e.com
59
"www.\u3042\u3044\u3046.com", // www.xn--l8jeg.com
60
"www.\u793A\u4F8B.com" // www.xn--fsq092h.com
61
};
62
63
for (String name : illegalNames) {
64
try {
65
System.out.println("Convering illegal IDN: " + name);
66
IDN.toASCII(name, IDN.USE_STD3_ASCII_RULES);
67
throw new Exception(
68
"Expected to get IllegalArgumentException for " + name);
69
} catch (IllegalArgumentException iae) {
70
// That's the right behavior.
71
}
72
}
73
74
for (String name : legalNames) {
75
System.out.println("Convering legal IDN: " + name);
76
System.out.println("\tThe ACE form is: " +
77
IDN.toASCII(name, IDN.USE_STD3_ASCII_RULES));
78
}
79
}
80
}
81
82