caddyfile: Prevent bad block opening tokens (#4655)

* caddyfile: Prevent bad block opening tokens

* Clarifying comments
This commit is contained in:
Francis Lavoie 2022-03-23 14:34:13 -04:00 committed by GitHub
parent c9b5e7f77b
commit 134b805644
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 2 deletions

View file

@ -494,6 +494,13 @@ func (p *parser) directive() error {
for p.Next() {
if p.Val() == "{" {
p.nesting++
if !p.isNextOnNewLine() && p.Token().wasQuoted == 0 {
return p.Err("Unexpected next token after '{' on same line")
}
} else if p.Val() == "{}" {
if p.isNextOnNewLine() && p.Token().wasQuoted == 0 {
return p.Err("Unexpected '{}' at end of line")
}
} else if p.isNewLine() && p.nesting == 0 {
p.cursor-- // read too far
break