Skip to content

Commit 980846a

Browse files
committed
fix: adjust TXT record formatting to preserve quotes for improved consistency
1 parent d0f25e5 commit 980846a

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

internal/stackitprovider/helper.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ func safeTTLToInt32(ttl endpoint.TTL) *int32 {
141141

142142
// formatTXTContent splits long TXT records into 255-character chunks separated by spaces.
143143
func formatTXTContent(content string) string {
144-
cleanContent := strings.Trim(content, "\"")
144+
cleanContent := strings.Trim(content, `"`)
145145

146146
if len(cleanContent) <= 255 {
147-
return `"` + cleanContent + `"`
147+
return content
148148
}
149149

150150
var chunks []string
@@ -161,11 +161,9 @@ func formatTXTContent(content string) string {
161161

162162
// unformatTXTContent reverses the DNS chunking and quoting process.
163163
func unformatTXTContent(content string) string {
164-
if !strings.HasPrefix(content, "\"") || !strings.HasSuffix(content, "\"") {
165-
return content
164+
if strings.Contains(content, `" "`) {
165+
return strings.ReplaceAll(content, `" "`, ``)
166166
}
167167

168-
trimmed := content[1 : len(content)-1]
169-
170-
return strings.ReplaceAll(trimmed, `" "`, "")
168+
return content
171169
}

internal/stackitprovider/helper_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,21 @@ func TestFormatTXTContent(t *testing.T) {
232232
{
233233
name: "Short string without quotes",
234234
content: "hello world",
235-
want: `"hello world"`,
235+
want: "hello world",
236236
},
237237
{
238238
name: "Short string with existing quotes",
239239
content: `"hello world"`,
240240
want: `"hello world"`,
241241
},
242242
{
243-
name: "Exactly 255 characters",
243+
name: "Exactly 255 characters unquoted",
244244
content: string255,
245+
want: string255,
246+
},
247+
{
248+
name: "Exactly 255 characters quoted",
249+
content: `"` + string255 + `"`,
245250
want: `"` + string255 + `"`,
246251
},
247252
{
@@ -283,17 +288,17 @@ func TestUnformatTXTContent(t *testing.T) {
283288
{
284289
name: "Single chunk quoted string",
285290
content: `"hello world"`,
286-
want: "hello world",
291+
want: `"hello world"`,
287292
},
288293
{
289294
name: "Two chunk string",
290295
content: `"hello" "world"`,
291-
want: "helloworld",
296+
want: `"helloworld"`,
292297
},
293298
{
294299
name: "Three chunk string",
295300
content: `"chunk1" "chunk2" "chunk3"`,
296-
want: "chunk1chunk2chunk3",
301+
want: `"chunk1chunk2chunk3"`,
297302
},
298303
}
299304

0 commit comments

Comments
 (0)