1
2
3
4
5
6
7 package idna
8
9 import "testing"
10
11
12
13
14
15
16
17
18
19
20 func TestLabelErrors(t *testing.T) {
21 encode := func(s string) string { s, _ = encode(acePrefix, s); return s }
22 type kind struct {
23 name string
24 f func(string) (string, error)
25 }
26 punyA := kind{"PunycodeA", punycode.ToASCII}
27 resolve := kind{"ResolveA", Lookup.ToASCII}
28 display := kind{"ToUnicode", Display.ToUnicode}
29 p := New(VerifyDNSLength(true), MapForLookup(), BidiRule())
30 lengthU := kind{"CheckLengthU", p.ToUnicode}
31 lengthA := kind{"CheckLengthA", p.ToASCII}
32 p = New(MapForLookup(), StrictDomainName(false))
33 std3 := kind{"STD3", p.ToASCII}
34 p = New(MapForLookup(), CheckHyphens(false))
35 hyphens := kind{"CheckHyphens", p.ToASCII}
36 p = New(MapForLookup(), Transitional(true))
37 transitional := kind{"Transitional", p.ToASCII}
38 p = New(MapForLookup(), Transitional(false))
39 nontransitional := kind{"Nontransitional", p.ToASCII}
40
41 testCases := []struct {
42 kind
43 input string
44 want string
45 wantErr string
46 }{
47 {lengthU, "", "", "A4"},
48 {lengthA, "", "", "A4"},
49
50 {lengthU, "xn--", "", "A4"},
51 {lengthU, "foo.xn--", "foo.", "A4"},
52 {lengthU, "xn--.foo", ".foo", "A4"},
53 {lengthU, "foo.xn--.bar", "foo..bar", "A4"},
54
55 {display, "xn--", "", ""},
56 {display, "foo.xn--", "foo.", ""},
57 {display, "xn--.foo", ".foo", ""},
58 {display, "foo.xn--.bar", "foo..bar", ""},
59
60 {lengthA, "a..b", "a..b", "A4"},
61 {punyA, ".b", ".b", ""},
62
63 {punyA, "\u3002b", "xn--b-83t", ""},
64 {punyA, "..b", "..b", ""},
65
66
67
68
69
70 {lengthA, ".b", "b", ""},
71 {lengthA, "\u3002b", "b", ""},
72 {lengthA, "..b", "b", ""},
73 {lengthA, "b..", "b..", ""},
74
75 {resolve, "a..b", "a..b", ""},
76 {resolve, ".b", "b", ""},
77 {resolve, "\u3002b", "b", ""},
78 {resolve, "..b", "b", ""},
79 {resolve, "b..", "b..", ""},
80 {resolve, "\xed", "", "P1"},
81
82
83 {punyA, "", "", ""},
84 {punyA, "*.foo.com", "*.foo.com", ""},
85 {punyA, "Foo.com", "Foo.com", ""},
86
87
88 {display, "*.foo.com", "*.foo.com", "P1"},
89 {std3, "*.foo.com", "*.foo.com", ""},
90
91
92 {display, "r3---sn-apo3qvuoxuxbt-j5pe.googlevideo.com", "r3---sn-apo3qvuoxuxbt-j5pe.googlevideo.com", "V2"},
93 {hyphens, "r3---sn-apo3qvuoxuxbt-j5pe.googlevideo.com", "r3---sn-apo3qvuoxuxbt-j5pe.googlevideo.com", ""},
94 {display, "-label-.com", "-label-.com", "V3"},
95 {hyphens, "-label-.com", "-label-.com", ""},
96
97
98
99 {resolve, "lab⒐be", "xn--labbe-zh9b", "P1"},
100 {display, "lab⒐be", "lab⒐be", "P1"},
101 {resolve, "plan⒐faß.de", "xn--planfass-c31e.de", "P1"},
102 {display, "Plan⒐faß.de", "plan⒐faß.de", "P1"},
103
104
105 {transitional, "Plan9faß.de", "plan9fass.de", ""},
106 {nontransitional, "Plan9faß.de", "xn--plan9fa-6va.de", ""},
107
108
109
110
111
112
113
114 {resolve, "日本⒈co.ßßß.de", "xn--co-wuw5954azlb.ssssss.de", "P1"},
115 {display, "日本⒈co.ßßß.de", "日本⒈co.ßßß.de", "P1"},
116
117 {resolve, "a\u200Cb", "ab", ""},
118 {display, "a\u200Cb", "a\u200Cb", "C"},
119
120 {resolve, encode("a\u200Cb"), encode("a\u200Cb"), "C"},
121 {display, "a\u200Cb", "a\u200Cb", "C"},
122
123 {resolve, "grﻋﺮﺑﻲ.de", "xn--gr-gtd9a1b0g.de", "B"},
124 {
125
126
127
128 display,
129 "gr\ufecb\ufeae\ufe91\ufef2.de",
130 "gr\u0639\u0631\u0628\u064a.de",
131 "B",
132 },
133
134 {resolve, "\u0671.\u03c3\u07dc", "xn--qib.xn--4xa21s", "B"},
135 {display, "\u0671.\u03c3\u07dc", "\u0671.\u03c3\u07dc", "B"},
136
137
138 {resolve, "a\u0323\u0322", "xn--jta191l", ""},
139 {display, "a\u0323\u0322", "\u1ea1\u0322", ""},
140
141
142
143
144 {resolve, encode("a\u0323\u0322") + ".com", "xn--a-tdbc.com", "V1"},
145 {display, encode("a\u0323\u0322") + ".com", "a\u0323\u0322.com", "V1"},
146 }
147
148 for _, tc := range testCases {
149 doTest(t, tc.f, tc.name, tc.input, tc.want, tc.wantErr)
150 }
151 }
152
View as plain text