summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2020-05-20 12:37:48 -0400
committerGitHub <noreply@github.com>2020-05-20 10:37:48 -0600
commitcc8fb488d360f609d7e3aae773ec80c661505367 (patch)
tree1d368f88b077fe5139377368667f0028af40f569 /caddyconfig
parentfae064262d9c40393d634660b94d36ce6703aa1c (diff)
httpcaddyfile: Improve error on matcher declared outside site block (#3431)
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/httpcaddyfile/httptype.go3
-rw-r--r--caddyconfig/httpcaddyfile/httptype_test.go9
2 files changed, 12 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go
index fddb095..42fee71 100644
--- a/caddyconfig/httpcaddyfile/httptype.go
+++ b/caddyconfig/httpcaddyfile/httptype.go
@@ -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)
}
diff --git a/caddyconfig/httpcaddyfile/httptype_test.go b/caddyconfig/httpcaddyfile/httptype_test.go
index 1bc2ddf..b0ee3ac 100644
--- a/caddyconfig/httpcaddyfile/httptype_test.go
+++ b/caddyconfig/httpcaddyfile/httptype_test.go
@@ -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{