From 05682b6fc83261d8627dfd8f360f0eee70174ba4 Mon Sep 17 00:00:00 2001 From: Daniel Peukert Date: Tue, 13 Oct 2020 16:43:57 +0200 Subject: [PATCH] Improve TXT record parsing --- internal/client.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/client.go b/internal/client.go index f2002a0..f1bbd11 100644 --- a/internal/client.go +++ b/internal/client.go @@ -37,7 +37,7 @@ func Discover(service string, host string) (string, error) { if len(addrs) > 0 { srvTarget := strings.TrimSuffix(addrs[0].Target, ".") - // If we found one, check for TXT records specifying the path + // If we found one, check for a TXT record specifying the path if srvTarget != "" { txtRecs, err := net.LookupTXT(fmt.Sprintf("_%vs._tcp.%v", service, host)) if dnsErr, ok := err.(*net.DNSError); ok { @@ -49,10 +49,11 @@ func Discover(service string, host string) (string, error) { } for _, txtRec := range txtRecs { - // This is not correct according to RFC 6763, but LookupTXT merges all constituent strings together + // This is not correct according to RFC 6763 sections 6.3 to 6.5, + // but LookupTXT merges all constituent strings together for _, txtRecKeyVal := range strings.Split(txtRec, " ") { - if strings.HasPrefix(txtRecKeyVal, "path=") { - path = strings.TrimPrefix(txtRecKeyVal, "path=") + if strings.HasPrefix(strings.ToLower(txtRecKeyVal), "path=") { + path = txtRecKeyVal[5:] break } }