Align PrevName with reference behavior

This commit is contained in:
Virgil 2026-04-04 08:47:28 +00:00
parent d2da43f7e8
commit fc3d05c557
2 changed files with 13 additions and 3 deletions

View file

@ -76,11 +76,12 @@ func GetNextName(tld string) string {
// PrevName returns the canonical predecessor for a top-level domain name.
//
// The helper lowercases and trims any trailing dot before applying the
// reference ordering logic.
// reference ordering logic. Empty trimmed names are invalid, matching the
// reference helper's assertion behavior.
func PrevName(tld string) string {
tld = trimFQDN(strings.ToLower(tld))
if len(tld) == 0 {
return "."
panic("dns.PrevName: invalid top-level domain")
}
last := tld[len(tld)-1] - 1

View file

@ -92,7 +92,6 @@ func TestPrevName(t *testing.T) {
}{
{name: "fqdn", in: "Foo-Bar.", want: "foo-baq\xff."},
{name: "label", in: "example", want: "exampld\xff."},
{name: "root", in: ".", want: "."},
}
for _, tc := range cases {
@ -105,3 +104,13 @@ func TestPrevName(t *testing.T) {
}
}
}
func TestPrevNameRejectsEmptyName(t *testing.T) {
defer func() {
if recover() == nil {
t.Fatal("PrevName should panic for an empty trimmed name")
}
}()
_ = PrevName(".")
}