From 09499bd07fe68a1900fa2b5b274ef74f12d42a6c Mon Sep 17 00:00:00 2001 From: Tom Thorogood Date: Fri, 4 Jan 2019 18:43:00 +1030 Subject: [PATCH] Use IsFqdn and Fqdn helper functions more (#892) --- defaults.go | 4 +--- labels.go | 2 +- msg.go | 2 +- scan.go | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/defaults.go b/defaults.go index a5dab628..6eb079d2 100644 --- a/defaults.go +++ b/defaults.go @@ -176,9 +176,7 @@ func IsDomainName(s string) (labels int, ok bool) { return 0, false } - if !strings.HasSuffix(s, ".") { - s += "." - } + s = Fqdn(s) // Each dot ends a segment of the name. Except for escaped dots (\.), which // are normal dots. diff --git a/labels.go b/labels.go index 577fc59d..bc182ba3 100644 --- a/labels.go +++ b/labels.go @@ -16,7 +16,7 @@ func SplitDomainName(s string) (labels []string) { fqdnEnd := 0 // offset of the final '.' or the length of the name idx := Split(s) begin := 0 - if s[len(s)-1] == '.' { + if IsFqdn(s) { fqdnEnd = len(s) - 1 } else { fqdnEnd = len(s) diff --git a/msg.go b/msg.go index 71e9241e..f5be33fc 100644 --- a/msg.go +++ b/msg.go @@ -244,7 +244,7 @@ func packDomainName(s string, msg []byte, off int, compression compressionMap, c } // If not fully qualified, error out. - if s[ls-1] != '.' { + if !IsFqdn(s) { return len(msg), ErrFqdn } diff --git a/scan.go b/scan.go index eaad5813..f067d850 100644 --- a/scan.go +++ b/scan.go @@ -1262,7 +1262,7 @@ func toAbsoluteName(name, origin string) (absolute string, ok bool) { } // check if name is already absolute - if name[len(name)-1] == '.' { + if IsFqdn(name) { return name, true }