Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
caddyfile: Fix `caddy fmt` nesting not decrementing (#4157)
* caddyfile(formatter): fix nesting not decrementing This is an extremely weird edge-case where if you had a environment variable {} on one line, a comment on the next line, and the closing of the block on the following line; the rest of the Caddyfile would be indented further than it should've been. ref; https://github.com/matthewpi/vscode-caddyfile-support/issues/13 * run gofmt * fmt: better way of handling edge case
Matthew Penner committed
May 10, 2021 at 12:01 UTC
bc2210247861340c644d9825ac2b2860f8c6e12a
3 files changed
+40
-1
caddyconfig/caddyfile/formatter.go
+1
@@ -78,6 +78,7 @@ func Format(input []byte) []byte {
78
if comment {
79
if ch == '\n' {
80
comment = false
81
+ space = true
82
nextLine()
83
continue
84
} else {
caddyconfig/caddyfile/formatter_test.go
+38
@@ -321,6 +321,44 @@ baz`,
321
foo
322
}`,
323
},
324
+ {
325
+ description: "matthewpi/vscode-caddyfile-support#13",
326
+ input: `{
327
+ email {$ACMEEMAIL}
328
+ #debug
329
+}
330
+
331
+block {
332
+}
333
+`,
334
+ expect: `{
335
+ email {$ACMEEMAIL}
336
+ #debug
337
+}
338
+
339
+block {
340
+}
341
+`,
342
+ },
343
+ {
344
+ description: "matthewpi/vscode-caddyfile-support#13 - bad formatting",
345
+ input: `{
346
+ email {$ACMEEMAIL}
347
+ #debug
348
+ }
349
+
350
+ block {
351
+ }
352
+`,
353
+ expect: `{
354
+ email {$ACMEEMAIL}
355
+ #debug
356
+}
357
+
358
+block {
359
+}
360
+`,
361
+ },
362
} {
363
// the formatter should output a trailing newline,
364
// even if the tests aren't written to expect that
modules/caddyhttp/replacer_test.go
+1
-1
@@ -173,7 +173,7 @@ eqp31wM9il1n+guTNyxJd+FzVAH+hCZE5K+tCgVDdVFUlDEHHbS/wqb2PSIoouLV
173
},
174
{
175
input: "{http.request.tls.client.certificate_pem}",
176
- expect: string(clientCert) + "\n", // returned value comes with a newline appended to it
176
+ expect: string(clientCert) + "\n", // returned value comes with a newline appended to it
177
},
178
} {
179
actual := repl.ReplaceAll(tc.input, "<empty>")