Skip to content

Commit

Permalink
fix(txt-suffix): avoid crash on domain without dot
Browse files Browse the repository at this point in the history
  • Loading branch information
titilambert committed Nov 20, 2024
1 parent b2e1a60 commit f1470b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions registry/txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,26 @@ func (pr affixNameMapper) isSuffix() bool {
}

func (pr affixNameMapper) toEndpointName(txtDNSName string) (endpointName string, recordType string) {
log.Debug("Getting endpoint from TXT record.")
lowerDNSName := strings.ToLower(txtDNSName)

// drop prefix
if pr.isPrefix() {
log.Debug("TXT record has a prefix.")
return pr.dropAffixExtractType(lowerDNSName)
}

// drop suffix
if pr.isSuffix() {
log.Debug("TXT record has a suffix.")
dc := strings.Count(pr.suffix, ".")
DNSName := strings.SplitN(lowerDNSName, ".", 2+dc)
domainWithSuffix := strings.Join(DNSName[:1+dc], ".")

r, rType := pr.dropAffixExtractType(domainWithSuffix)
if !strings.Contains(lowerDNSName, ".") {
return r, rType
}
return r + "." + DNSName[1+dc], rType
}
return "", ""
Expand Down
7 changes: 7 additions & 0 deletions registry/txt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,13 @@ func TestToEndpointNameNewTXT(t *testing.T) {
recordType: "A",
txtDomain: "fooa-example.com",
},
{
name: "suffix",
mapper: newaffixNameMapper("", "foo", ""),
domain: "example",
recordType: "AAAA",
txtDomain: "aaaa-examplefoo",
},
{
name: "suffix",
mapper: newaffixNameMapper("", "foo", ""),
Expand Down

0 comments on commit f1470b1

Please sign in to comment.