Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix presence test to produce an error when it's not a map or a message #922

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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