Use IsFqdn and Fqdn helper functions more (#892)

This commit is contained in:
Tom Thorogood 2019-01-04 18:43:00 +10:30 committed by Miek Gieben
parent b9e1e7529b
commit 09499bd07f
4 changed files with 4 additions and 6 deletions

View File

@ -176,9 +176,7 @@ func IsDomainName(s string) (labels int, ok bool) {
return 0, false return 0, false
} }
if !strings.HasSuffix(s, ".") { s = Fqdn(s)
s += "."
}
// Each dot ends a segment of the name. Except for escaped dots (\.), which // Each dot ends a segment of the name. Except for escaped dots (\.), which
// are normal dots. // are normal dots.

View File

@ -16,7 +16,7 @@ func SplitDomainName(s string) (labels []string) {
fqdnEnd := 0 // offset of the final '.' or the length of the name fqdnEnd := 0 // offset of the final '.' or the length of the name
idx := Split(s) idx := Split(s)
begin := 0 begin := 0
if s[len(s)-1] == '.' { if IsFqdn(s) {
fqdnEnd = len(s) - 1 fqdnEnd = len(s) - 1
} else { } else {
fqdnEnd = len(s) fqdnEnd = len(s)

2
msg.go
View File

@ -244,7 +244,7 @@ func packDomainName(s string, msg []byte, off int, compression compressionMap, c
} }
// If not fully qualified, error out. // If not fully qualified, error out.
if s[ls-1] != '.' { if !IsFqdn(s) {
return len(msg), ErrFqdn return len(msg), ErrFqdn
} }

View File

@ -1262,7 +1262,7 @@ func toAbsoluteName(name, origin string) (absolute string, ok bool) {
} }
// check if name is already absolute // check if name is already absolute
if name[len(name)-1] == '.' { if IsFqdn(name) {
return name, true return name, true
} }