Skip to content

Commit

Permalink
httpcaddyfile: Fix panic when parsing route with matchers (#3746)
Browse files Browse the repository at this point in the history
Fixes #3745
  • Loading branch information
francislavoie authored Sep 22, 2020
1 parent fe27f9c commit be6daa5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion caddyconfig/httpcaddyfile/directives.go
Original file line number Diff line number Diff line change
Expand Up @@ -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--
}
}

Expand Down
31 changes: 31 additions & 0 deletions caddytest/integration/caddyfile_adapt/matchers_in_route.txt
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
}
}
}
}

0 comments on commit be6daa5

Please sign in to comment.