caddyfile: Stricter parsing, error for brace on new line (#5505)

This commit is contained in:
Francis Lavoie 2023-04-20 14:43:51 -04:00 committed by GitHub
parent c6ac350a3b
commit 53b6fab125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 533 additions and 521 deletions

View File

@ -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")

View File

@ -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}},

File diff suppressed because it is too large Load Diff

View File

@ -373,6 +373,7 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
// the rest of the config is specified by the user
// using the reverse_proxy directive syntax
dispenser.Next() // consume the directive name
err = rpHandler.UnmarshalCaddyfile(dispenser)
if err != nil {
return nil, err

View File

@ -216,6 +216,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
// the rest of the config is specified by the user
// using the reverse_proxy directive syntax
dispenser.Next() // consume the directive name
err = rpHandler.UnmarshalCaddyfile(dispenser)
if err != nil {
return nil, err