diff --git a/internal/export/idna/idna10.0.0.go b/internal/export/idna/idna10.0.0.go index 0e7571d1..01bdbb16 100644 --- a/internal/export/idna/idna10.0.0.go +++ b/internal/export/idna/idna10.0.0.go @@ -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} @@ -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"} } } diff --git a/internal/export/idna/idna10.0.0_test.go b/internal/export/idna/idna10.0.0_test.go index c3365bc6..ff9218dd 100644 --- a/internal/export/idna/idna10.0.0_test.go +++ b/internal/export/idna/idna10.0.0_test.go @@ -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. @@ -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 diff --git a/internal/export/idna/idna9.0.0.go b/internal/export/idna/idna9.0.0.go index f217b1a4..017335c9 100644 --- a/internal/export/idna/idna9.0.0.go +++ b/internal/export/idna/idna9.0.0.go @@ -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} @@ -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"} } } diff --git a/internal/export/idna/idna9.0.0_test.go b/internal/export/idna/idna9.0.0_test.go index 91a1e90d..393e7074 100644 --- a/internal/export/idna/idna9.0.0_test.go +++ b/internal/export/idna/idna9.0.0_test.go @@ -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