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:
@@ -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":
|
||||
// Nothing special.
|
||||
case "TXT":
|
||||
if cap(rc.TxtStrings) == 1 {
|
||||
record.Content = "\"" + rc.TxtStrings[0] + "\""
|
||||
} else if cap(rc.TxtStrings) > 1 {
|
||||
record.Content = ""
|
||||
for _, str := range rc.TxtStrings {
|
||||
record.Content = record.Content + " \"" + str + "\""
|
||||
}
|
||||
record.Content = record.Content[1:len(record.Content)]
|
||||
txtStrings := make([]string, len(rc.TxtStrings))
|
||||
copy(txtStrings, rc.TxtStrings)
|
||||
|
||||
// Escape quotes
|
||||
for i := range txtStrings {
|
||||
txtStrings[i] = fmt.Sprintf(`"%s"`, strings.ReplaceAll(txtStrings[i], `"`, `\"`))
|
||||
}
|
||||
|
||||
record.Content = strings.Join(txtStrings, " ")
|
||||
case "MX":
|
||||
record.Priority = rc.MxPreference
|
||||
record.Content = strings.TrimSuffix(rc.GetTargetField(), ".")
|
||||
|
Reference in New Issue
Block a user