diff options
author | Francis Lavoie <[email protected]> | 2023-04-20 14:43:51 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2023-04-20 18:43:51 +0000 |
commit | 53b6fab125f3f2f149d59fcfe13b1e8b1735da56 (patch) | |
tree | 242a8e721d7ea6fe5c8dddbd090e08ec74d27da0 /caddyconfig/caddyfile | |
parent | c6ac350a3b53feb1dfcc24d82421cd20da61a163 (diff) | |
download | caddy-53b6fab125f3f2f149d59fcfe13b1e8b1735da56.tar.gz caddy-53b6fab125f3f2f149d59fcfe13b1e8b1735da56.zip |
caddyfile: Stricter parsing, error for brace on new line (#5505)
Diffstat (limited to 'caddyconfig/caddyfile')
-rw-r--r-- | caddyconfig/caddyfile/parse.go | 3 | ||||
-rw-r--r-- | caddyconfig/caddyfile/parse_test.go | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go index c65acae96..ab84086af 100644 --- a/caddyconfig/caddyfile/parse.go +++ b/caddyconfig/caddyfile/parse.go @@ -520,6 +520,9 @@ func (p *parser) directive() error { if !p.isNextOnNewLine() && p.Token().wasQuoted == 0 { return p.Err("Unexpected next token after '{' on same line") } + if p.isNewLine() { + return p.Err("Unexpected '{' on a new line; did you mean to place the '{' on the previous line?") + } } else if p.Val() == "{}" { if p.isNextOnNewLine() && p.Token().wasQuoted == 0 { return p.Err("Unexpected '{}' at end of line") diff --git a/caddyconfig/caddyfile/parse_test.go b/caddyconfig/caddyfile/parse_test.go index ad8683b1f..bbae7855d 100644 --- a/caddyconfig/caddyfile/parse_test.go +++ b/caddyconfig/caddyfile/parse_test.go @@ -293,6 +293,14 @@ func TestParseOneAndImport(t *testing.T) { // Unexpected next token after '{' on same line {`localhost dir1 { a b }`, true, []string{"localhost"}, []int{}}, + + // Unexpected '{' on a new line + {`localhost + dir1 + { + a b + }`, true, []string{"localhost"}, []int{}}, + // Workaround with quotes {`localhost dir1 "{" a b "}"`, false, []string{"localhost"}, []int{5}}, |