Skip to content

Commit b129b8e

Browse files
hnakamurmpvl
authored andcommitted
idna: add test for domains containing non-ASCII dots
Change-Id: I1011371968c2a548378c7490212a39989a9de75e Reviewed-on: https://go-review.googlesource.com/38284 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
1 parent 66aacef commit b129b8e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

idna/idna_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,70 @@ func TestIDNA(t *testing.T) {
3939
}
4040
}
4141

42+
func TestIDNASeparators(t *testing.T) {
43+
type subCase struct {
44+
unicode string
45+
wantASCII string
46+
wantErr bool
47+
}
48+
49+
testCases := []struct {
50+
name string
51+
profile *Profile
52+
subCases []subCase
53+
}{
54+
{
55+
name: "Punycode", profile: Punycode,
56+
subCases: []subCase{
57+
{"example\u3002jp", "xn--examplejp-ck3h", false},
58+
{"東京\uFF0Ejp", "xn--jp-l92cn98g071o", false},
59+
{"大阪\uFF61jp", "xn--jp-ku9cz72u463f", false},
60+
},
61+
},
62+
{
63+
name: "Lookup", profile: Lookup,
64+
subCases: []subCase{
65+
{"example\u3002jp", "example.jp", false},
66+
{"東京\uFF0Ejp", "xn--1lqs71d.jp", false},
67+
{"大阪\uFF61jp", "xn--pssu33l.jp", false},
68+
},
69+
},
70+
{
71+
name: "Display", profile: Display,
72+
subCases: []subCase{
73+
{"example\u3002jp", "example.jp", false},
74+
{"東京\uFF0Ejp", "xn--1lqs71d.jp", false},
75+
{"大阪\uFF61jp", "xn--pssu33l.jp", false},
76+
},
77+
},
78+
{
79+
name: "Registration", profile: Registration,
80+
subCases: []subCase{
81+
{"example\u3002jp", "", true},
82+
{"東京\uFF0Ejp", "", true},
83+
{"大阪\uFF61jp", "", true},
84+
},
85+
},
86+
}
87+
for _, tc := range testCases {
88+
t.Run(tc.name, func(t *testing.T) {
89+
for _, c := range tc.subCases {
90+
gotA, err := tc.profile.ToASCII(c.unicode)
91+
if c.wantErr {
92+
if err == nil {
93+
t.Errorf("ToASCII(%q): got no error, but an error expected", c.unicode)
94+
}
95+
} else {
96+
if err != nil {
97+
t.Errorf("ToASCII(%q): got err=%v, but no error expected", c.unicode, err)
98+
} else if gotA != c.wantASCII {
99+
t.Errorf("ToASCII(%q): got %q, want %q", c.unicode, gotA, c.wantASCII)
100+
}
101+
}
102+
}
103+
})
104+
}
105+
}
106+
42107
// TODO(nigeltao): test errors, once we've specified when ToASCII and ToUnicode
43108
// return errors.

0 commit comments

Comments
 (0)