Skip to content

Commit

Permalink
httpcaddyfile: Improve error on matcher declared outside site block
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed May 20, 2020
1 parent fae0642 commit 9b4fc52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions caddyconfig/httpcaddyfile/httptype.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
originalServerBlocks := make([]serverBlock, 0, len(inputServerBlocks))
for i, sblock := range inputServerBlocks {
for j, k := range sblock.Keys {
if j == 0 && strings.HasPrefix(k, "@") {
return nil, warnings, fmt.Errorf("cannot define a matcher outside of a site block: '%s'", k)
}
if _, ok := sbKeys[k]; ok {
return nil, warnings, fmt.Errorf("duplicate site address not allowed: '%s' in %v (site block %d, key %d)", k, sblock.Keys, i, j)
}
Expand Down
9 changes: 9 additions & 0 deletions caddyconfig/httpcaddyfile/httptype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func TestMatcherSyntax(t *testing.T) {
expectWarn: false,
expectError: false,
},
{
input: `@matcher {
path /matcher-not-allowed/outside-of-site-block/*
}
http://localhost
`,
expectWarn: false,
expectError: true,
},
} {

adapter := caddyfile.Adapter{
Expand Down

0 comments on commit 9b4fc52

Please sign in to comment.