From 2ebdda69715489ea5c692686b5972edc34da532e Mon Sep 17 00:00:00 2001 From: Julius Rickert Date: Tue, 17 Jan 2023 16:57:58 +0100 Subject: [PATCH] HOSTINGDE: Fix & simplify string quoting (#1945) Co-authored-by: Tom Limoncelli --- providers/hostingde/types.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/providers/hostingde/types.go b/providers/hostingde/types.go index 6bced7cae..c6b71a616 100644 --- a/providers/hostingde/types.go +++ b/providers/hostingde/types.go @@ -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(), ".")