Skip to content

Commit

Permalink
NAMEDOTCOM: BUGFIX: TXT records add unneeded quotes (#3260)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlimoncelli authored Dec 27, 2024
1 parent 2f55b6c commit a8990ae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 71 deletions.
10 changes: 5 additions & 5 deletions providers/namedotcom/auditrecords.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ func AuditRecords(records []*models.RecordConfig) []error {

a.Add("SRV", rejectif.SrvHasNullTarget) // Last verified 2020-12-28

a.Add("TXT", MaxLengthNDC) // Last verified 2021-03-01
a.Add("TXT", MaxLengthNDC) // Last verified 2024-12-17

a.Add("TXT", rejectif.TxtIsEmpty) // Last verified 2023-11-18
a.Add("TXT", rejectif.TxtHasDoubleQuotes) // Last verified 2024-12-17

a.Add("TXT", rejectif.TxtHasBackslash) // Last verified 2023-11-18
// Backslashes may be allowed in the API but the current
// encodeTxt/decodeTxt functions don't support backslashes.
a.Add("TXT", rejectif.TxtHasTrailingSpace) // Last verified 2024-12-17

a.Add("TXT", rejectif.TxtIsEmpty) // Last verified 2024-12-17

return a.Audit(records)
}
Expand Down
25 changes: 2 additions & 23 deletions providers/namedotcom/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package namedotcom
import (
"errors"
"fmt"
"regexp"
"strings"

"github.com/StackExchange/dnscontrol/v4/models"
"github.com/StackExchange/dnscontrol/v4/pkg/diff"
"github.com/StackExchange/dnscontrol/v4/pkg/txtutil"
"github.com/namedotcom/go/namecom"
)

Expand Down Expand Up @@ -95,7 +93,7 @@ func toRecord(r *namecom.Record, origin string) *models.RecordConfig {
rc.SetLabelFromFQDN(fqdn, origin)
switch rtype := r.Type; rtype { // #rtype_variations
case "TXT":
rc.SetTargetTXTs(decodeTxt(r.Answer))
rc.SetTargetTXT(r.Answer)
case "MX":
if err := rc.SetTargetMX(uint16(r.Priority), r.Answer); err != nil {
panic(fmt.Errorf("unparsable MX record received from ndc: %w", err))
Expand Down Expand Up @@ -155,7 +153,7 @@ func (n *namedotcomProvider) createRecord(rc *models.RecordConfig, domain string
case "A", "AAAA", "ANAME", "CNAME", "MX", "NS":
// nothing
case "TXT":
record.Answer = txtutil.EncodeQuoted(rc.GetTargetTXTJoined())
record.Answer = rc.GetTargetTXTJoined()
case "SRV":
if rc.GetTargetField() == "." {
return errors.New("SRV records with empty targets are not supported (as of 2019-11-05, the API returns 'Parameter Value Error - Invalid Srv Format')")
Expand All @@ -171,25 +169,6 @@ func (n *namedotcomProvider) createRecord(rc *models.RecordConfig, domain string
return err
}

// finds a string surrounded by quotes that might contain an escaped quote character.
var quotedStringRegexp = regexp.MustCompile(`"((?:[^"\\]|\\.)*)"`)

// decodeTxt decodes the TXT record as received from name.com and
// returns the list of strings.
// NB(tlim): This is very similar to txtutil.ParseQuoted. Maybe replace it some day?
func decodeTxt(s string) []string {

if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' {
txtStrings := []string{}
for _, t := range quotedStringRegexp.FindAllStringSubmatch(s, -1) {
txtString := strings.Replace(t[1], `\"`, `"`, -1)
txtStrings = append(txtStrings, txtString)
}
return txtStrings
}
return []string{s}
}

func (n *namedotcomProvider) deleteRecord(id int32, domain string) error {
request := &namecom.DeleteRecordRequest{
DomainName: domain,
Expand Down
43 changes: 0 additions & 43 deletions providers/namedotcom/records_test.go

This file was deleted.

0 comments on commit a8990ae

Please sign in to comment.