Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/text: *Profile.process to throw labelError if verifyDNSLength = true and s ends with trailing dot. #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions internal/export/idna/idna10.0.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (p *Profile) process(s string, toASCII bool) (string, error) {
// TODO: allow for a quick check of the tables data.
// It seems like we should only create this error on ToASCII, but the
// UTS 46 conformance tests suggests we should always check this.
if err == nil && p.verifyDNSLength && s == "" {
if err == nil && p.verifyDNSLength && (s == "" || s[len(s)-1] == '.') {
err = &labelError{s, "A4"}
}
labels := labelIter{orig: s}
Expand Down Expand Up @@ -413,12 +413,9 @@ func (p *Profile) process(s string, toASCII bool) (string, error) {
}
s = labels.result()
if toASCII && p.verifyDNSLength && err == nil {
// Compute the length of the domain name minus the root label and its dot.
// Compute the length of the domain name.
n := len(s)
if n > 0 && s[n-1] == '.' {
n--
}
if len(s) < 1 || n > 253 {
if n < 1 || n > 253 {
err = &labelError{s, "A4"}
}
}
Expand Down
12 changes: 11 additions & 1 deletion internal/export/idna/idna10.0.0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ func TestLabelErrors(t *testing.T) {
{lengthA, ".b", ".b", "A4"},
{lengthA, "\u3002b", ".b", "A4"},
{lengthA, "..b", "..b", "A4"},
{lengthA, "b..", "b..", ""},
{lengthA, "b.", "b.", "A4"},
{lengthA, "ƀ.", "xn--lha.", "A4"},
{lengthA, "b..", "b..", "A4"},
{lengthA, "ƀ..", "xn--lha..", "A4"},
{lengthA, "b...", "b...", "A4"},
{lengthA, "ƀ...", "xn--lha...", "A4"},

// Sharpened Bidi rules for Unicode 10.0.0. Apply for ALL labels in ANY
// of the labels is RTL.
Expand All @@ -80,7 +85,12 @@ func TestLabelErrors(t *testing.T) {
{resolve, ".b", ".b", ""},
{resolve, "\u3002b", ".b", ""},
{resolve, "..b", "..b", ""},
{resolve, "b.", "b.", ""},
{resolve, "ƀ.", "xn--lha.", ""},
{resolve, "b..", "b..", ""},
{resolve, "ƀ..", "xn--lha..", ""},
{resolve, "b...", "b...", ""},
{resolve, "ƀ...", "xn--lha...", ""},
{resolve, "\xed", "", "P1"},

// Raw punycode
Expand Down
9 changes: 3 additions & 6 deletions internal/export/idna/idna9.0.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (p *Profile) process(s string, toASCII bool) (string, error) {
}
// It seems like we should only create this error on ToASCII, but the
// UTS 46 conformance tests suggests we should always check this.
if err == nil && p.verifyDNSLength && s == "" {
if err == nil && p.verifyDNSLength && (s == "" || s[len(s)-1] == '.') {
err = &labelError{s, "A4"}
}
labels := labelIter{orig: s}
Expand Down Expand Up @@ -404,12 +404,9 @@ func (p *Profile) process(s string, toASCII bool) (string, error) {
}
s = labels.result()
if toASCII && p.verifyDNSLength && err == nil {
// Compute the length of the domain name minus the root label and its dot.
// Compute the length of the domain name.
n := len(s)
if n > 0 && s[n-1] == '.' {
n--
}
if len(s) < 1 || n > 253 {
if n < 1 || n > 253 {
err = &labelError{s, "A4"}
}
}
Expand Down
12 changes: 11 additions & 1 deletion internal/export/idna/idna9.0.0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,23 @@ func TestLabelErrors(t *testing.T) {
{lengthA, ".b", "b", ""},
{lengthA, "\u3002b", "b", ""},
{lengthA, "..b", "b", ""},
{lengthA, "b..", "b..", ""},
{lengthA, "b.", "b.", "A4"},
{lengthA, "ƀ.", "xn--lha.", "A4"},
{lengthA, "b..", "b..", "A4"},
{lengthA, "ƀ..", "xn--lha..", "A4"},
{lengthA, "b...", "b...", "A4"},
{lengthA, "ƀ...", "xn--lha...", "A4"},

{resolve, "a..b", "a..b", ""},
{resolve, ".b", "b", ""},
{resolve, "\u3002b", "b", ""},
{resolve, "..b", "b", ""},
{resolve, "b.", "b.", ""},
{resolve, "ƀ.", "xn--lha.", ""},
{resolve, "b..", "b..", ""},
{resolve, "ƀ..", "xn--lha..", ""},
{resolve, "b...", "b...", ""},
{resolve, "ƀ...", "xn--lha...", ""},
{resolve, "\xed", "", "P1"},

// Raw punycode
Expand Down