1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

HOSTINGDE: Fix & simplify string quoting (#1945)

Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
Julius Rickert
2023-01-17 16:57:58 +01:00
committed by GitHub
parent 8344f5c7c9
commit 2ebdda6971

View File

@@ -158,15 +158,15 @@ func recordToNative(rc *models.RecordConfig) *record {
case "A", "AAAA", "ALIAS", "CAA", "CNAME", "DNSKEY", "DS", "NS", "NSEC", "NSEC3", "NSEC3PARAM", "PTR", "RRSIG", "SSHFP", "TSLA": case "A", "AAAA", "ALIAS", "CAA", "CNAME", "DNSKEY", "DS", "NS", "NSEC", "NSEC3", "NSEC3PARAM", "PTR", "RRSIG", "SSHFP", "TSLA":
// Nothing special. // Nothing special.
case "TXT": case "TXT":
if cap(rc.TxtStrings) == 1 { txtStrings := make([]string, len(rc.TxtStrings))
record.Content = "\"" + rc.TxtStrings[0] + "\"" copy(txtStrings, rc.TxtStrings)
} else if cap(rc.TxtStrings) > 1 {
record.Content = "" // Escape quotes
for _, str := range rc.TxtStrings { for i := range txtStrings {
record.Content = record.Content + " \"" + str + "\"" txtStrings[i] = fmt.Sprintf(`"%s"`, strings.ReplaceAll(txtStrings[i], `"`, `\"`))
}
record.Content = record.Content[1:len(record.Content)]
} }
record.Content = strings.Join(txtStrings, " ")
case "MX": case "MX":
record.Priority = rc.MxPreference record.Priority = rc.MxPreference
record.Content = strings.TrimSuffix(rc.GetTargetField(), ".") record.Content = strings.TrimSuffix(rc.GetTargetField(), ".")