Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
httpcaddyfile: Fix panic when parsing route with matchers (#3746)
Fixes #3745
Francis Lavoie committed
Sep 22, 2020 at 19:37 UTC
be6daa5fd46edc9f66a5129347482b38e22bf103
2 files changed
+36
-1
caddyconfig/httpcaddyfile/directives.go
+5
-1
@@ -304,13 +304,17 @@ func parseSegmentAsConfig(h Helper) ([]ConfigValue, error) {
304
}
305
306
// find and extract any embedded matcher definitions in this scope
307
- for i, seg := range segments {
307
+ for i := 0; i < len(segments); i++ {
308
+ seg := segments[i]
309
if strings.HasPrefix(seg.Directive(), matcherPrefix) {
310
+ // parse, then add the matcher to matcherDefs
311
err := parseMatcherDefinitions(caddyfile.NewDispenser(seg), matcherDefs)
312
if err != nil {
313
return nil, err
314
}
315
+ // remove the matcher segment (consumed), then step back the loop
316
segments = append(segments[:i], segments[i+1:]...)
317
+ i--
318
}
319
}
320
caddytest/integration/caddyfile_adapt/matchers_in_route.txt
new
+31
@@ -0,0 +1,31 @@
1
+:80 {
2
+ route {
3
+ # unused matchers should not panic
4
+ # see https://github.com/caddyserver/caddy/issues/3745
5
+ @matcher1 path /path1
6
+ @matcher2 path /path2
7
+ }
8
+}
9
+----------
10
+{
11
+ "apps": {
12
+ "http": {
13
+ "servers": {
14
+ "srv0": {
15
+ "listen": [
16
+ ":80"
17
+ ],
18
+ "routes": [
19
+ {
20
+ "handle": [
21
+ {
22
+ "handler": "subroute"
23
+ }
24
+ ]
25
+ }
26
+ ]
27
+ }
28
+ }
29
+ }
30
+ }
31
+}
\ No newline at end of file