Skip to content

Commit dcedd34

Browse files
neildxhit
authored andcommitted
internal/export/idna: use nontransitional processing in Go 1.18
Updates golang/go#46001 Updates golang/go#47510 Change-Id: I1e978a3c6230abfd0b1aaab0c7343b33dda1ba64 Reviewed-on: https://go-review.googlesource.com/c/text/+/359634 Trust: Damien Neil <[email protected]> Run-TryBot: Damien Neil <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Timothy Gu <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent d02d3ac commit dcedd34

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
lines changed

internal/export/idna/example_test.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,26 @@ import (
1313
func ExampleProfile() {
1414
// Raw Punycode has no restrictions and does no mappings.
1515
fmt.Println(idna.ToASCII(""))
16-
fmt.Println(idna.ToASCII("*.faß.com"))
17-
fmt.Println(idna.Punycode.ToASCII("*.faß.com"))
16+
fmt.Println(idna.ToASCII("*.GÖPHER.com"))
17+
fmt.Println(idna.Punycode.ToASCII("*.GÖPHER.com"))
1818

19-
// Rewrite IDN for lookup. This (currently) uses transitional mappings to
20-
// find a balance between IDNA2003 and IDNA2008 compatibility.
19+
// Rewrite IDN for lookup.
2120
fmt.Println(idna.Lookup.ToASCII(""))
22-
fmt.Println(idna.Lookup.ToASCII("www.faß.com"))
21+
fmt.Println(idna.Lookup.ToASCII("www.GÖPHER.com"))
2322

24-
// Convert an IDN to ASCII for registration purposes. This changes the
25-
// encoding, but reports an error if the input was illformed.
26-
fmt.Println(idna.Registration.ToASCII(""))
27-
fmt.Println(idna.Registration.ToASCII("www.faß.com"))
23+
// Convert an IDN to ASCII for registration purposes.
24+
// This reports an error if the input was illformed.
25+
fmt.Println(idna.Registration.ToASCII("www.GÖPHER.com"))
26+
fmt.Println(idna.Registration.ToASCII("www.göpher.com"))
2827

2928
// Output:
3029
// <nil>
31-
// *.xn--fa-hia.com <nil>
32-
// *.xn--fa-hia.com <nil>
30+
// *.xn--GPHER-1oa.com <nil>
31+
// *.xn--GPHER-1oa.com <nil>
3332
// <nil>
34-
// www.fass.com <nil>
35-
// idna: invalid label ""
36-
// www.xn--fa-hia.com <nil>
33+
// www.xn--gpher-jua.com <nil>
34+
// www.xn--GPHER-1oa.com idna: disallowed rune U+0047
35+
// www.xn--gpher-jua.com <nil>
3736
}
3837

3938
func ExampleNew() {

internal/export/idna/go118.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build go1.18
6+
// +build go1.18
7+
8+
package idna
9+
10+
// Transitional processing is disabled by default in Go 1.18.
11+
// https://golang.org/issue/47510
12+
const transitionalLookup = false

internal/export/idna/idna10.0.0.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ var (
284284

285285
punycode = &Profile{}
286286
lookup = &Profile{options{
287-
transitional: true,
287+
transitional: transitionalLookup,
288288
useSTD3Rules: true,
289289
checkHyphens: true,
290290
checkJoiners: true,

internal/export/idna/idna10.0.0_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestLabelErrors(t *testing.T) {
102102
// Chrome, modern Firefox, Safari, and IE.
103103
{resolve, "lab⒐be", "xn--labbe-zh9b", "P1"}, // encode("lab⒐be")
104104
{display, "lab⒐be", "lab⒐be", "P1"},
105-
{resolve, "plan⒐faß.de", "xn--planfass-c31e.de", "P1"}, // encode("plan⒐fass") + ".de"
105+
{transitional, "plan⒐faß.de", "xn--planfass-c31e.de", "P1"}, // encode("plan⒐fass") + ".de"
106106
{display, "Plan⒐faß.de", "plan⒐faß.de", "P1"},
107107

108108
// Transitional vs Nontransitional processing
@@ -115,10 +115,10 @@ func TestLabelErrors(t *testing.T) {
115115
// punycode on the result using transitional mapping.
116116
// Firefox 49.0.1 goes haywire on this string and prints a bunch of what
117117
// seems to be nested punycode encodings.
118-
{resolve, "日本⒈co.ßßß.de", "xn--co-wuw5954azlb.ssssss.de", "P1"},
118+
{transitional, "日本⒈co.ßßß.de", "xn--co-wuw5954azlb.ssssss.de", "P1"},
119119
{display, "日本⒈co.ßßß.de", "日本⒈co.ßßß.de", "P1"},
120120

121-
{resolve, "a\u200Cb", "ab", ""},
121+
{transitional, "a\u200Cb", "ab", ""},
122122
{display, "a\u200Cb", "a\u200Cb", "C"},
123123

124124
{resolve, encode("a\u200Cb"), encode("a\u200Cb"), "C"},
@@ -153,3 +153,11 @@ func TestLabelErrors(t *testing.T) {
153153
doTest(t, tc.f, tc.name, tc.input, tc.want, tc.wantErr)
154154
}
155155
}
156+
157+
func TestTransitionalDefault(t *testing.T) {
158+
want := "xn--strae-oqa.de"
159+
if transitionalLookup {
160+
want = "strasse.de"
161+
}
162+
doTest(t, Lookup.ToASCII, "Lookup", "straße.de", want, "")
163+
}

internal/export/idna/idna_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestProfiles(t *testing.T) {
4545
VerifyDNSLength(true),
4646
BidiRule(),
4747
)},
48-
{"Lookup", lookup, New(MapForLookup(), BidiRule(), Transitional(true))},
48+
{"Lookup", lookup, New(MapForLookup(), BidiRule(), Transitional(transitionalLookup))},
4949
{"Display", display, New(MapForLookup(), BidiRule())},
5050
}
5151
for _, tc := range testCases {

internal/export/idna/pre_go118.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !go1.18
6+
// +build !go1.18
7+
8+
package idna
9+
10+
const transitionalLookup = true

0 commit comments

Comments
 (0)