From 635f075f187ac73c65e6939b8402494469a4d627 Mon Sep 17 00:00:00 2001
From: Matthew Holt <mholt@users.noreply.github.com>
Date: Wed, 16 Dec 2020 15:22:16 -0700
Subject: [PATCH] caddyfile: Fix minor bug in formatter

---
 caddyconfig/caddyfile/formatter.go      |  2 ++
 caddyconfig/caddyfile/formatter_test.go | 11 +++++++++++
 2 files changed, 13 insertions(+)

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