Skip to content

Commit 7278b25

Browse files
committed
internal/export/idna: update for post-Unicode 10 idna changes
Unicode 11 changed the test file format, and we've never updated to the new format nor kept up with algorithmic changes. Unicode 16 dropped the disallowed_STD3 variants from the IdnaMappingTable.txt file and made more algorithmic changes. Update to the new test format and implement the new algorithm. Note that unicode16 is a constant, so disabled version-specific code is dead code. For golang/go#77266. Change-Id: Ic9d0a6a7a5922c12383de12264c2a6d38b951047 Reviewed-on: https://go-review.googlesource.com/c/text/+/737402 Reviewed-by: Roland Shoemaker <roland@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent f964ad8 commit 7278b25

8 files changed

Lines changed: 210 additions & 52 deletions

File tree

internal/export/idna/common_test.go

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/export/idna/conformance_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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.26
6+
57
package idna
68

79
import (
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2018 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.26
6+
7+
package idna
8+
9+
import (
10+
"testing"
11+
12+
"golang.org/x/text/internal/gen"
13+
"golang.org/x/text/internal/testtext"
14+
"golang.org/x/text/internal/ucd"
15+
)
16+
17+
func TestConformance(t *testing.T) {
18+
testtext.SkipIfNotLong(t)
19+
20+
r := gen.OpenUnicodeFile("idna", "", "IdnaTestV2.txt")
21+
defer r.Close()
22+
23+
section := "main"
24+
p := ucd.New(r)
25+
transitional := New(Transitional(true), VerifyDNSLength(true), BidiRule(), MapForLookup())
26+
nonTransitional := New(VerifyDNSLength(true), BidiRule(), MapForLookup())
27+
for p.Next() {
28+
var (
29+
src = def(unescape(p.String(0)), "")
30+
toUnicode = def(unescape(p.String(1)), src)
31+
toUnicodeErr = p.String(2)
32+
toASCIIN = def(unescape(p.String(3)), toUnicode)
33+
toASCIINErr = def(p.String(4), toUnicodeErr)
34+
toASCIIT = def(unescape(p.String(5)), toASCIIN)
35+
toASCIITErr = def(p.String(6), toASCIINErr)
36+
)
37+
doTest(t, nonTransitional.ToUnicode, section+":ToUnicode", src, toUnicode, toUnicodeErr)
38+
doTest(t, nonTransitional.ToASCII, section+":ToASCII:N", src, toASCIIN, toASCIINErr)
39+
doTest(t, transitional.ToASCII, section+":ToASCII:T", src, toASCIIT, toASCIITErr)
40+
}
41+
}
42+
43+
func def(field, fallback string) string {
44+
if field == "" {
45+
return fallback
46+
}
47+
if field == `""` {
48+
return ""
49+
}
50+
return field
51+
}

internal/export/idna/gen.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,7 @@ func (c *normCompacter) Print(w io.Writer) (retErr error) {
279279
p("\n}\n\n")
280280
return
281281
}
282+
283+
func allowedSTD3(r rune) bool {
284+
return r >= 0x80 || '0' <= r && r <= '9' || 'a' <= r && r <= 'z' || r == '-' || r == '.'
285+
}

internal/export/idna/gen_common.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import (
1616
)
1717

1818
func catFromEntry(p *ucd.Parser) (cat category) {
19+
// Note: As of Unicode 16, IdnaMappingTable.txt no longer includes
20+
// disallowed_STD3_valid and disallowed_STD3_mapped.
21+
// It is up to us to bring them back with our definition of disallowedSTD3,
22+
// which is exactly the runes from Unicode 15.
1923
r := p.Rune(0)
24+
idna2008status := p.String(3)
2025
switch s := p.String(1); s {
2126
case "valid":
2227
cat = valid
@@ -35,9 +40,9 @@ func catFromEntry(p *ucd.Parser) (cat category) {
3540
default:
3641
log.Fatalf("%U: Unknown category %q", r, s)
3742
}
38-
if s := p.String(3); s != "" {
43+
if s := idna2008status; s != "" {
3944
if cat != valid {
40-
log.Fatalf(`%U: %s defined for %q; want "valid"`, r, s, p.String(1))
45+
log.Fatalf(`%U: %s defined for %q/%v; want "valid"`, r, s, p.String(1), cat)
4146
}
4247
switch s {
4348
case "NV8":

0 commit comments

Comments
 (0)