From 83d7e99a216f10b0326386af6f57c9a64e83c6de Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 21 Nov 2015 18:01:18 +0100 Subject: [PATCH] =?UTF-8?q?Expose=20rr.Txt=20as=20[]string=20instead=20of?= =?UTF-8?q?=20joining=20it=20with=20=E2=80=9C|=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Joining the different fields into a single string is problematic when the fields contain the separator character “|” themselves. As an example, I’ve named my chromecast “Hendrix|test”, and this happens when I print a ServiceEntry: ServiceEntry: &{Name:Hendrix|test._googlecast._tcp.local. Host:Hendrix|test.local. AddrV4:10.0.0.184 AddrV6: Port:8009 Info:id=3fc948dbfebcf5d7ec77d7b043dce81e|ve=04|md=Chromecast Audio|ic=/setup/icon.png|fn=Hendrix|test|ca=4|st=0|bs=FA8FCA928304|rs= Addr:10.0.0.184 hasTXT:true sent:true} When using strings.Split, I would not correctly parse the fn= field. With the new InfoFields member, this problem can be avoided entirely. --- client.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index a7359ae..ab1c80d 100644 --- a/client.go +++ b/client.go @@ -15,12 +15,13 @@ import ( // ServiceEntry is returned after we query for a service type ServiceEntry struct { - Name string - Host string - AddrV4 net.IP - AddrV6 net.IP - Port int - Info string + Name string + Host string + AddrV4 net.IP + AddrV6 net.IP + Port int + Info string + InfoFields []string Addr net.IP // @Deprecated @@ -258,6 +259,7 @@ func (c *client) query(params *QueryParam) error { // Pull out the txt inp = ensureName(inprogress, rr.Hdr.Name) inp.Info = strings.Join(rr.Txt, "|") + inp.InfoFields = rr.Txt inp.hasTXT = true case *dns.A: