Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 22:15 UTC
caddyfile: prevent adding trailing space on line before env variable (#7215)
Arpan Saha committed
Aug 27, 2025 at 02:43 UTC
6d73d85c1fd3d20acaaadc0fb69e3f562d92f685
2 files changed
+17
-2
caddyconfig/caddyfile/formatter.go
+2
-2
@@ -224,7 +224,7 @@ func Format(input []byte) []byte {
224
openBrace = false
225
if beginningOfLine {
226
indent()
227
- } else if !openBraceSpace {
227
+ } else if !openBraceSpace || !unicode.IsSpace(last) {
228
write(' ')
229
}
230
write('{')
@@ -241,7 +241,7 @@ func Format(input []byte) []byte {
241
case ch == '{':
242
openBrace = true
243
openBraceSpace = spacePrior && !beginningOfLine
244
- if openBraceSpace {
244
+ if openBraceSpace && newLines == 0 {
245
write(' ')
246
}
247
openBraceWritten = false
caddyconfig/caddyfile/formatter_test.go
+15
@@ -444,6 +444,21 @@ block2 {
444
input: "block {respond \"All braces should remain: {{now | date `2006`}}\"}",
445
expect: "block {respond \"All braces should remain: {{now | date `2006`}}\"}",
446
},
447
+ {
448
+ description: "No trailing space on line before env variable",
449
+ input: `{
450
+ a
451
+
452
+ {$ENV_VAR}
453
+}
454
+`,
455
+ expect: `{
456
+ a
457
+
458
+ {$ENV_VAR}
459
+}
460
+`,
461
+ },
462
} {
463
// the formatter should output a trailing newline,
464
// even if the tests aren't written to expect that