Skip to content

Commit

Permalink
Fix presence test to produce an error when it's not a map or a message (
Browse files Browse the repository at this point in the history
  • Loading branch information
l46kok committed Apr 16, 2024
1 parent 94cbc9d commit 2337cc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 0 additions & 3 deletions interpreter/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,9 +1283,6 @@ func refQualify(adapter types.Adapter, obj any, idx ref.Val, presenceTest, prese
}
return val, true, nil
default:
if presenceTest {
return nil, false, nil
}
return nil, false, missingKey(idx)
}
}
Expand Down
14 changes: 12 additions & 2 deletions interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"time"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/wrapperspb"

"github.com/google/cel-go/checker"
"github.com/google/cel-go/common"
Expand All @@ -40,9 +42,7 @@ import (
"github.com/google/cel-go/parser"

exprpb "google.golang.org/genproto/googleapis/api/expr/v1alpha1"
structpb "google.golang.org/protobuf/types/known/structpb"
tpb "google.golang.org/protobuf/types/known/timestamppb"
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"

proto2pb "github.com/google/cel-go/test/proto2pb"
proto3pb "github.com/google/cel-go/test/proto3pb"
Expand Down Expand Up @@ -1445,6 +1445,16 @@ func testData(t testing.TB) []testCase {
}, NewAttributePattern("a").QualInt(0)),
out: types.NewUnknown(2, types.QualifyAttribute[uint64](types.NewAttributeTrail("a"), 0)),
},
{
name: "invalid_presence_test_on_int_literal",
expr: `has(dyn(1).invalid)`,
err: "no such key: invalid",
},
{
name: "invalid_presence_test_on_list_literal",
expr: `has(dyn([]).invalid)`,
err: "unsupported index type 'string' in list",
},
}
}

Expand Down

0 comments on commit 2337cc0

Please sign in to comment.