Skip to content

Commit bb1c798

Browse files
TimothyGuneild
authored andcommitted
internal/export/idna: make Transitional an actual toggle
Previously, it always enabled transitional processing instead of toggling, despite the fact that it took a boolean argument. For golang/go#30940. Change-Id: I00ad51ec55abfb2de28deb8c98f949989ece1099 Reviewed-on: https://go-review.googlesource.com/c/text/+/317729 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Damien Neil <[email protected]> Trust: Damien Neil <[email protected]> Run-TryBot: Damien Neil <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 5bd84dd commit bb1c798

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

internal/export/idna/conformance_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.10
6+
// +build go1.10
7+
58
package idna
69

710
import (

internal/export/idna/idna10.0.0.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ type Option func(*options)
5959
// Transitional sets a Profile to use the Transitional mapping as defined in UTS
6060
// #46. This will cause, for example, "ß" to be mapped to "ss". Using the
6161
// transitional mapping provides a compromise between IDNA2003 and IDNA2008
62-
// compatibility. It is used by most browsers when resolving domain names. This
62+
// compatibility. It is used by some browsers when resolving domain names. This
6363
// option is only meaningful if combined with MapForLookup.
6464
func Transitional(transitional bool) Option {
65-
return func(o *options) { o.transitional = true }
65+
return func(o *options) { o.transitional = transitional }
6666
}
6767

6868
// VerifyDNSLength sets whether a Profile should fail if any of the IDN parts

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func TestLabelErrors(t *testing.T) {
3434
std3 := kind{"STD3", p.ToASCII}
3535
p = New(MapForLookup(), CheckHyphens(false))
3636
hyphens := kind{"CheckHyphens", p.ToASCII}
37+
p = New(MapForLookup(), Transitional(true))
38+
transitional := kind{"Transitional", p.ToASCII}
39+
p = New(MapForLookup(), Transitional(false))
40+
nontransitional := kind{"Nontransitional", p.ToASCII}
3741

3842
testCases := []struct {
3943
kind
@@ -95,14 +99,16 @@ func TestLabelErrors(t *testing.T) {
9599
{hyphens, "-label-.com", "-label-.com", ""},
96100

97101
// Don't map U+2490 (DIGIT NINE FULL STOP). This is the behavior of
98-
// Chrome, Safari, and IE. Firefox will first map ⒐ to 9. and return
99-
// lab9.be.
102+
// Chrome, modern Firefox, Safari, and IE.
100103
{resolve, "lab⒐be", "xn--labbe-zh9b", "P1"}, // encode("lab⒐be")
101104
{display, "lab⒐be", "lab⒐be", "P1"},
102-
103105
{resolve, "plan⒐faß.de", "xn--planfass-c31e.de", "P1"}, // encode("plan⒐fass") + ".de"
104106
{display, "Plan⒐faß.de", "plan⒐faß.de", "P1"},
105107

108+
// Transitional vs Nontransitional processing
109+
{transitional, "Plan9faß.de", "plan9fass.de", ""},
110+
{nontransitional, "Plan9faß.de", "xn--plan9fa-6va.de", ""},
111+
106112
// Chrome 54.0 recognizes the error and treats this input verbatim as a
107113
// search string.
108114
// Safari 10.0 (non-conform spec) decomposes "⒈" and computes the

internal/export/idna/idna9.0.0.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ type Option func(*options)
5858
// Transitional sets a Profile to use the Transitional mapping as defined in UTS
5959
// #46. This will cause, for example, "ß" to be mapped to "ss". Using the
6060
// transitional mapping provides a compromise between IDNA2003 and IDNA2008
61-
// compatibility. It is used by most browsers when resolving domain names. This
61+
// compatibility. It is used by some browsers when resolving domain names. This
6262
// option is only meaningful if combined with MapForLookup.
6363
func Transitional(transitional bool) Option {
64-
return func(o *options) { o.transitional = true }
64+
return func(o *options) { o.transitional = transitional }
6565
}
6666

6767
// VerifyDNSLength sets whether a Profile should fail if any of the IDN parts

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func TestLabelErrors(t *testing.T) {
3434
std3 := kind{"STD3", p.ToASCII}
3535
p = New(MapForLookup(), CheckHyphens(false))
3636
hyphens := kind{"CheckHyphens", p.ToASCII}
37+
p = New(MapForLookup(), Transitional(true))
38+
transitional := kind{"Transitional", p.ToASCII}
39+
p = New(MapForLookup(), Transitional(false))
40+
nontransitional := kind{"Nontransitional", p.ToASCII}
3741

3842
testCases := []struct {
3943
kind
@@ -91,14 +95,16 @@ func TestLabelErrors(t *testing.T) {
9195
{hyphens, "-label-.com", "-label-.com", ""},
9296

9397
// Don't map U+2490 (DIGIT NINE FULL STOP). This is the behavior of
94-
// Chrome, Safari, and IE. Firefox will first map ⒐ to 9. and return
95-
// lab9.be.
98+
// Chrome, modern Firefox, Safari, and IE.
9699
{resolve, "lab⒐be", "xn--labbe-zh9b", "P1"}, // encode("lab⒐be")
97100
{display, "lab⒐be", "lab⒐be", "P1"},
98-
99101
{resolve, "plan⒐faß.de", "xn--planfass-c31e.de", "P1"}, // encode("plan⒐fass") + ".de"
100102
{display, "Plan⒐faß.de", "plan⒐faß.de", "P1"},
101103

104+
// Transitional vs Nontransitional processing
105+
{transitional, "Plan9faß.de", "plan9fass.de", ""},
106+
{nontransitional, "Plan9faß.de", "xn--plan9fa-6va.de", ""},
107+
102108
// Chrome 54.0 recognizes the error and treats this input verbatim as a
103109
// search string.
104110
// Safari 10.0 (non-conform spec) decomposes "⒈" and computes the

0 commit comments

Comments
 (0)