caddyconfig: Fix indentation of multiline strings in fmt (#7425) (#7433)

This commit is contained in:
Paulo Henrique
2026-01-13 17:22:23 -03:00
committed by GitHub
parent 62134d65af
commit e9d290de2f
2 changed files with 21 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ import (
"bytes"
"io"
"slices"
"strings"
"unicode"
)
@@ -209,6 +210,15 @@ func Format(input []byte) []byte {
}
}
if strings.Contains(quotes, "`") {
if ch == '`' && space && !beginningOfLine {
write(' ')
}
write(ch)
space = false
continue
}
if unicode.IsSpace(ch) {
space = true
heredocEscaped = false

View File

@@ -464,6 +464,17 @@ block2 {
}
`,
},
{
description: "issue #7425: multiline backticked string indentation",
input: `https://localhost:8953 {
respond ` + "`" + `Here are some random numbers:
{{randNumeric 16}}
Hope this helps.` + "`" + `
}`,
expect: "https://localhost:8953 {\n\trespond `Here are some random numbers:\n\n{{randNumeric 16}}\n\nHope this helps.`\n}",
},
} {
// the formatter should output a trailing newline,
// even if the tests aren't written to expect that