We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents dcfa07b + a9c1caf commit 1a2e2a0Copy full SHA for 1a2e2a0
pkg/cel/conversions.go
@@ -43,6 +43,8 @@ func GoNativeType(v ref.Val) (interface{}, error) {
43
return v.Value().(float64), nil
44
case types.StringType:
45
return v.Value().(string), nil
46
+ case types.BytesType:
47
+ return v.Value().([]byte), nil
48
case types.ListType:
49
return convertList(v)
50
case types.MapType:
pkg/cel/conversions_test.go
@@ -83,3 +83,30 @@ func TestGoNativeType_ComplexNested(t *testing.T) {
83
_, err = json.Marshal(native)
84
assert.NoError(t, err, "Should be JSON marshallable")
85
}
86
+
87
+func TestGoNativeType_Bytes(t *testing.T) {
88
+ env, err := cel.NewEnv()
89
+ require.NoError(t, err)
90
91
+ ast, issues := env.Compile(`b"hello world"`)
92
+ require.NoError(t, issues.Err())
93
94
+ prog, err := env.Program(ast)
95
96
97
+ val, _, err := prog.Eval(map[string]interface{}{})
98
99
100
+ native, err := GoNativeType(val)
101
102
103
+ // Check type
104
+ bytes, ok := native.([]byte)
105
+ require.True(t, ok, "Expected []byte, got %T", native)
106
+ assert.Equal(t, []byte("hello world"), bytes)
107
108
+ // Check JSON marshalling
109
+ marshalled, err := json.Marshal(native)
110
+ assert.NoError(t, err, "Should be JSON marshallable")
111
+ assert.NotEmpty(t, marshalled)
112
+}
0 commit comments