diff --git a/caddyconfig/caddyfile/formatter.go b/caddyconfig/caddyfile/formatter.go index 627054166..862021923 100644 --- a/caddyconfig/caddyfile/formatter.go +++ b/caddyconfig/caddyfile/formatter.go @@ -78,6 +78,8 @@ func Format(input []byte) []byte { if comment { if ch == '\n' { comment = false + nextLine() + continue } else { write(ch) continue diff --git a/caddyconfig/caddyfile/formatter_test.go b/caddyconfig/caddyfile/formatter_test.go index 6751ecaac..6cae20d7e 100644 --- a/caddyconfig/caddyfile/formatter_test.go +++ b/caddyconfig/caddyfile/formatter_test.go @@ -310,6 +310,17 @@ baz`, input: `redir / /some/#/path`, expect: `redir / /some/#/path`, }, + { + description: "brace does not fold into comment above", + input: `# comment +{ + foo +}`, + expect: `# comment +{ + foo +}`, + }, } { // the formatter should output a trailing newline, // even if the tests aren't written to expect that