caddyfile: prevent adding trailing space on line before env variable (#7215)

This commit is contained in:
Arpan Saha 2025-08-27 02:43:54 +05:30 committed by GitHub
parent e0a8f9541d
commit 6d73d85c1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -224,7 +224,7 @@ func Format(input []byte) []byte {
openBrace = false
if beginningOfLine {
indent()
} else if !openBraceSpace {
} else if !openBraceSpace || !unicode.IsSpace(last) {
write(' ')
}
write('{')
@ -241,7 +241,7 @@ func Format(input []byte) []byte {
case ch == '{':
openBrace = true
openBraceSpace = spacePrior && !beginningOfLine
if openBraceSpace {
if openBraceSpace && newLines == 0 {
write(' ')
}
openBraceWritten = false

View File

@ -444,6 +444,21 @@ block2 {
input: "block {respond \"All braces should remain: {{now | date `2006`}}\"}",
expect: "block {respond \"All braces should remain: {{now | date `2006`}}\"}",
},
{
description: "No trailing space on line before env variable",
input: `{
a
{$ENV_VAR}
}
`,
expect: `{
a
{$ENV_VAR}
}
`,
},
} {
// the formatter should output a trailing newline,
// even if the tests aren't written to expect that