summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2020-09-22 19:37:15 -0400
committerGitHub <noreply@github.com>2020-09-22 17:37:15 -0600
commitbe6daa5fd46edc9f66a5129347482b38e22bf103 (patch)
tree4c1bdbb1bb1cabfe90146f674819ebaf3e52759e
parentfe27f9cf0c7f53c891c35fbcf6a6b3219e85fd0a (diff)
httpcaddyfile: Fix panic when parsing route with matchers (#3746)
Fixes #3745
-rw-r--r--caddyconfig/httpcaddyfile/directives.go6
-rw-r--r--caddytest/integration/caddyfile_adapt/matchers_in_route.txt31
2 files changed, 36 insertions, 1 deletions
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go
index e9ba44c..5d9a339 100644
--- a/caddyconfig/httpcaddyfile/directives.go
+++ b/caddyconfig/httpcaddyfile/directives.go
@@ -304,13 +304,17 @@ func parseSegmentAsConfig(h Helper) ([]ConfigValue, error) {
}
// find and extract any embedded matcher definitions in this scope
- for i, seg := range segments {
+ for i := 0; i < len(segments); i++ {
+ seg := segments[i]
if strings.HasPrefix(seg.Directive(), matcherPrefix) {
+ // parse, then add the matcher to matcherDefs
err := parseMatcherDefinitions(caddyfile.NewDispenser(seg), matcherDefs)
if err != nil {
return nil, err
}
+ // remove the matcher segment (consumed), then step back the loop
segments = append(segments[:i], segments[i+1:]...)
+ i--
}
}
diff --git a/caddytest/integration/caddyfile_adapt/matchers_in_route.txt b/caddytest/integration/caddyfile_adapt/matchers_in_route.txt
new file mode 100644
index 0000000..01609b0
--- /dev/null
+++ b/caddytest/integration/caddyfile_adapt/matchers_in_route.txt
@@ -0,0 +1,31 @@
+:80 {
+ route {
+ # unused matchers should not panic
+ # see https://github.com/caddyserver/caddy/issues/3745
+ @matcher1 path /path1
+ @matcher2 path /path2
+ }
+}
+----------
+{
+ "apps": {
+ "http": {
+ "servers": {
+ "srv0": {
+ "listen": [
+ ":80"
+ ],
+ "routes": [
+ {
+ "handle": [
+ {
+ "handler": "subroute"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ }
+ }
+} \ No newline at end of file