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

Simplify CanonicalName #1494

Merged
merged 1 commit into from
Nov 2, 2023
Merged
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
19 changes: 7 additions & 12 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net"
"strconv"
"strings"
"unicode"
)

const hexDigit = "0123456789abcdef"
Expand Down Expand Up @@ -330,19 +329,15 @@ func Fqdn(s string) string {
}

// CanonicalName returns the domain name in canonical form. A name in canonical
// form is lowercase and fully qualified. See Section 6.2 in RFC 4034.
// According to the RFC all uppercase US-ASCII letters in the owner name of the
// RR areeplaced by the corresponding lowercase US-ASCII letters.
// form is lowercase and fully qualified. Only US-ASCII letters are affected. See
// Section 6.2 in RFC 4034.
func CanonicalName(s string) string {
var result strings.Builder
for _, ch := range s {
if unicode.IsUpper(ch) && (ch >= 0x00 && ch <= 0x7F) {
result.WriteRune(unicode.ToLower(ch))
} else {
result.WriteRune(ch)
return strings.Map(func(r rune) rune {
if r >= 'A' && r <= 'Z' {
r += 'a' - 'A'
}
}
return Fqdn(result.String())
return r
}, Fqdn(s))
}

// Copied from the official Go code.
Expand Down
Loading