summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/vars.go
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2023-03-02 11:01:54 -0500
committerGitHub <noreply@github.com>2023-03-02 09:01:54 -0700
commit85375861f6a903da9af8aa665552a6546d075c9f (patch)
tree2320c5024f6a5e0682233a7de89d33b5364c690c /modules/caddyhttp/vars.go
parentf6bab8ba85b231ea0930282e684c0040001059e6 (diff)
caddyhttp: Fix `vars_regexp` matcher with placeholders (#5408)
Changed to match the `vars` matcher's logic for handling placeholders
Diffstat (limited to 'modules/caddyhttp/vars.go')
-rw-r--r--modules/caddyhttp/vars.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/modules/caddyhttp/vars.go b/modules/caddyhttp/vars.go
index b4e1d89..d2d7f62 100644
--- a/modules/caddyhttp/vars.go
+++ b/modules/caddyhttp/vars.go
@@ -255,9 +255,18 @@ func (m MatchVarsRE) Provision(ctx caddy.Context) error {
func (m MatchVarsRE) Match(r *http.Request) bool {
vars := r.Context().Value(VarsCtxKey).(map[string]any)
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
- for k, rm := range m {
+ for key, val := range m {
+ var varValue any
+ if strings.HasPrefix(key, "{") &&
+ strings.HasSuffix(key, "}") &&
+ strings.Count(key, "{") == 1 {
+ varValue, _ = repl.Get(strings.Trim(key, "{}"))
+ } else {
+ varValue = vars[key]
+ }
+
var varStr string
- switch vv := vars[k].(type) {
+ switch vv := varValue.(type) {
case string:
varStr = vv
case fmt.Stringer:
@@ -267,13 +276,9 @@ func (m MatchVarsRE) Match(r *http.Request) bool {
default:
varStr = fmt.Sprintf("%v", vv)
}
- valExpanded := repl.ReplaceAll(varStr, "")
- if match := rm.Match(valExpanded, repl); match {
- return match
- }
- replacedVal := repl.ReplaceAll(k, "")
- if match := rm.Match(replacedVal, repl); match {
+ valExpanded := repl.ReplaceAll(varStr, "")
+ if match := val.Match(valExpanded, repl); match {
return match
}
}