mirror of
https://github.com/caddyserver/caddy.git
synced 2025-09-14 16:18:03 -04:00
caddyfile: prevent adding trailing space on line before env variable (#7215)
This commit is contained in:
parent
e0a8f9541d
commit
6d73d85c1f
@ -224,7 +224,7 @@ func Format(input []byte) []byte {
|
|||||||
openBrace = false
|
openBrace = false
|
||||||
if beginningOfLine {
|
if beginningOfLine {
|
||||||
indent()
|
indent()
|
||||||
} else if !openBraceSpace {
|
} else if !openBraceSpace || !unicode.IsSpace(last) {
|
||||||
write(' ')
|
write(' ')
|
||||||
}
|
}
|
||||||
write('{')
|
write('{')
|
||||||
@ -241,7 +241,7 @@ func Format(input []byte) []byte {
|
|||||||
case ch == '{':
|
case ch == '{':
|
||||||
openBrace = true
|
openBrace = true
|
||||||
openBraceSpace = spacePrior && !beginningOfLine
|
openBraceSpace = spacePrior && !beginningOfLine
|
||||||
if openBraceSpace {
|
if openBraceSpace && newLines == 0 {
|
||||||
write(' ')
|
write(' ')
|
||||||
}
|
}
|
||||||
openBraceWritten = false
|
openBraceWritten = false
|
||||||
|
@ -444,6 +444,21 @@ block2 {
|
|||||||
input: "block {respond \"All braces should remain: {{now | date `2006`}}\"}",
|
input: "block {respond \"All braces should remain: {{now | date `2006`}}\"}",
|
||||||
expect: "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,
|
// the formatter should output a trailing newline,
|
||||||
// even if the tests aren't written to expect that
|
// even if the tests aren't written to expect that
|
||||||
|
Loading…
x
Reference in New Issue
Block a user