aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMohammed Al Sahaf <[email protected]>2024-05-17 01:11:21 +0300
committerMohammed Al Sahaf <[email protected]>2024-05-17 01:11:21 +0300
commite8f8fc2948734c83f7aecc31b1dd39af169355f1 (patch)
tree239038429473eb173de588a175d325a45a877ed7
parent44860482d2e38f10dc13b42e6ab277919ab4b5f1 (diff)
downloadcaddy-e8f8fc2948734c83f7aecc31b1dd39af169355f1.tar.gz
caddy-e8f8fc2948734c83f7aecc31b1dd39af169355f1.zip
matchers: support `null` value in expression matchercel-support-null
-rw-r--r--modules/caddyhttp/celmatcher.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/modules/caddyhttp/celmatcher.go b/modules/caddyhttp/celmatcher.go
index d4016478e..2ea28acbb 100644
--- a/modules/caddyhttp/celmatcher.go
+++ b/modules/caddyhttp/celmatcher.go
@@ -37,6 +37,7 @@ import (
"github.com/google/cel-go/interpreter/functions"
"github.com/google/cel-go/parser"
"go.uber.org/zap"
+ "google.golang.org/protobuf/types/known/structpb"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
@@ -566,8 +567,9 @@ func celMatcherJSONMacroExpander(funcName string) parser.MacroExpander {
if !isStringPlaceholder {
return nil, eh.NewError(entry.ID(), "matcher map keys must be string literals")
}
+ isNull := entry.AsMapEntry().Value().AsLiteral().Type() == types.NullType
isStringListPlaceholder := isCELStringExpr(entry.AsMapEntry().Value()) ||
- isCELStringListLiteral(entry.AsMapEntry().Value())
+ isCELStringListLiteral(entry.AsMapEntry().Value()) || isNull
if !isStringListPlaceholder {
return nil, eh.NewError(entry.AsMapEntry().Value().ID(), "matcher map values must be string or list literals")
}
@@ -598,6 +600,8 @@ func CELValueToMapStrList(data ref.Val) (map[string][]string, error) {
mapStrListStr := make(map[string][]string, len(mapStrIface))
for k, v := range mapStrIface {
switch val := v.(type) {
+ case structpb.NullValue:
+ mapStrListStr[k] = nil
case string:
mapStrListStr[k] = []string{val}
case types.String:
@@ -704,7 +708,7 @@ var (
placeholderRegexp = regexp.MustCompile(`{([a-zA-Z][\w.-]+)}`)
placeholderExpansion = `caddyPlaceholder(request, "${1}")`
- CELTypeJSON = cel.MapType(cel.StringType, cel.DynType)
+ CELTypeJSON = cel.MapType(cel.StringType, cel.AnyType)
)
var httpRequestObjectType = cel.ObjectType("http.Request")