Skip to content

Commit 46e8923

Browse files
committed
fix: fix parsing TXT owner records; fix #126
1 parent 3b2c150 commit 46e8923

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
7777
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
7878
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
7979
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
80-
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk=
81-
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
8280
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
8381
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
8482
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=

internal/adguard/provider.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func endpointSupported(e *endpoint.Endpoint) bool {
188188
}
189189

190190
func deserializeToEndpoint(rule string) (*endpoint.Endpoint, error) {
191-
// format: "|DNS.NAME^dnsrewrite=NOERROR;RECORD_TYPE;TARGET"
191+
// format: "|DNS.NAME^dnsrewrite=NOERROR;RECORD_TYPE;TARGET,important"
192192
p := strings.SplitN(rule, ";", 3)
193193
if len(p) != 3 {
194194
return nil, errNotManaged
@@ -200,14 +200,21 @@ func deserializeToEndpoint(rule string) (*endpoint.Endpoint, error) {
200200
if len(dp) != 2 {
201201
return nil, fmt.Errorf("invalid rule: %s", rule)
202202
}
203+
203204
d := strings.TrimPrefix(dp[0], "|")
204-
t := strings.Split(p[2], ",")
205+
206+
// TXT records can contain commas, so we need to ensure we don't split them incorrectly
207+
t := p[2]
208+
lc := strings.LastIndex(p[2], ",")
209+
if lc > 0 {
210+
t = p[2][:lc]
211+
}
205212

206213
// see serializeToString for the format
207214
r := &endpoint.Endpoint{
208215
RecordType: p[1],
209216
DNSName: d,
210-
Targets: endpoint.Targets{t[0]},
217+
Targets: endpoint.Targets{t},
211218
}
212219

213220
return r, nil

internal/adguard/provider_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ func TestDeserializeToEndpoint(t *testing.T) {
157157
text: "|domain.com^$dnsrewrite=NOERROR;TXT;external-dns-txt",
158158
endpoint: &endpoint.Endpoint{DNSName: "domain.com", RecordType: endpoint.RecordTypeTXT, Targets: []string{"external-dns-txt"}},
159159
},
160+
{
161+
name: "TXT owner record",
162+
text: "|whoami.local^$dnsrewrite=NOERROR;TXT;heritage=external-dns,external-dns/owner=default,external-dns/resource=httproute/default/whoami-http-route,important",
163+
endpoint: &endpoint.Endpoint{DNSName: "whoami.local", RecordType: endpoint.RecordTypeTXT, Targets: []string{"heritage=external-dns,external-dns/owner=default,external-dns/resource=httproute/default/whoami-http-route"}},
164+
},
160165
{
161166
name: "long TXT record",
162167
text: "|domain.com^$dnsrewrite=NOERROR;TXT;\"external-dns-txt; d=abc; v=...\"",
@@ -268,6 +273,7 @@ func TestRecords(t *testing.T) {
268273
"|domain.com^$dnsrewrite=NOERROR;A;2.2.2.2",
269274
"|domain.com^$dnsrewrite=NOERROR;AAAA;1111:1111::1",
270275
"|other.org^$dnsrewrite=NOERROR;A;3.3.3.3",
276+
"|whoami.local^$dnsrewrite=NOERROR;TXT;heritage=external-dns,external-dns/owner=default,external-dns/resource=httproute/default/whoami-http-route,important",
271277
},
272278
},
273279
endpoints: []*endpoint.Endpoint{
@@ -293,6 +299,13 @@ func TestRecords(t *testing.T) {
293299
"3.3.3.3",
294300
},
295301
},
302+
{
303+
DNSName: "whoami.local",
304+
RecordType: endpoint.RecordTypeTXT,
305+
Targets: []string{
306+
"heritage=external-dns,external-dns/owner=default,external-dns/resource=httproute/default/whoami-http-route",
307+
},
308+
},
296309
},
297310
},
298311
{

0 commit comments

Comments
 (0)