summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--caddyconfig/caddyfile/formatter.go3
-rw-r--r--caddyconfig/caddyfile/formatter_test.go9
-rwxr-xr-xcaddyconfig/caddyfile/lexer.go2
-rwxr-xr-xcaddyconfig/caddyfile/lexer_test.go20
4 files changed, 28 insertions, 6 deletions
diff --git a/caddyconfig/caddyfile/formatter.go b/caddyconfig/caddyfile/formatter.go
index 2c97f3b..6270541 100644
--- a/caddyconfig/caddyfile/formatter.go
+++ b/caddyconfig/caddyfile/formatter.go
@@ -131,9 +131,6 @@ func Format(input []byte) []byte {
//////////////////////////////////////////////////////////
if ch == '#' {
- if !spacePrior && !beginningOfLine {
- write(' ')
- }
comment = true
}
diff --git a/caddyconfig/caddyfile/formatter_test.go b/caddyconfig/caddyfile/formatter_test.go
index 25bd7fa..6751eca 100644
--- a/caddyconfig/caddyfile/formatter_test.go
+++ b/caddyconfig/caddyfile/formatter_test.go
@@ -201,7 +201,7 @@ c
}
d {
- e #f
+ e#f
# g
}
@@ -229,7 +229,7 @@ bar"
j {
"\"k\" l m"
}`,
- expect: `"a \"b\" " #c
+ expect: `"a \"b\" "#c
d
e {
@@ -305,6 +305,11 @@ bar "{\"key\":34}"`,
baz`,
},
+ {
+ description: "hash within string is not a comment",
+ input: `redir / /some/#/path`,
+ expect: `redir / /some/#/path`,
+ },
} {
// the formatter should output a trailing newline,
// even if the tests aren't written to expect that
diff --git a/caddyconfig/caddyfile/lexer.go b/caddyconfig/caddyfile/lexer.go
index d9968ff..568d15c 100755
--- a/caddyconfig/caddyfile/lexer.go
+++ b/caddyconfig/caddyfile/lexer.go
@@ -141,7 +141,7 @@ func (l *lexer) next() bool {
continue
}
- if ch == '#' {
+ if ch == '#' && len(val) == 0 {
comment = true
}
if comment {
diff --git a/caddyconfig/caddyfile/lexer_test.go b/caddyconfig/caddyfile/lexer_test.go
index 734006e..c8c941a 100755
--- a/caddyconfig/caddyfile/lexer_test.go
+++ b/caddyconfig/caddyfile/lexer_test.go
@@ -78,6 +78,26 @@ func TestLexer(t *testing.T) {
},
},
{
+ input: `host:123 {
+ # hash inside string is not a comment
+ redir / /some/#/path
+ }`,
+ expected: []Token{
+ {Line: 1, Text: "host:123"},
+ {Line: 1, Text: "{"},
+ {Line: 3, Text: "redir"},
+ {Line: 3, Text: "/"},
+ {Line: 3, Text: "/some/#/path"},
+ {Line: 4, Text: "}"},
+ },
+ },
+ {
+ input: "# comment at beginning of file\n# comment at beginning of line\nhost:123",
+ expected: []Token{
+ {Line: 3, Text: "host:123"},
+ },
+ },
+ {
input: `a "quoted value" b
foobar`,
expected: []Token{