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: disallow null in empty object assertion #430

Merged
merged 4 commits into from
Jul 21, 2024
Merged
Changes from 3 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
7 changes: 7 additions & 0 deletions pkg/engine/assert/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@

func (n mapNode) assert(ctx context.Context, path *field.Path, value any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) {
var errs field.ErrorList
// if we assert against an empty object, value is expected to be not nil
if len(n) == 0 {
if value == nil {
errs = append(errs, field.Invalid(path, value, "invalid value, must not be null"))

Check warning on line 46 in pkg/engine/assert/parse.go

View check run for this annotation

Codecov / codecov/patch

pkg/engine/assert/parse.go#L44-L46

Added lines #L44 - L46 were not covered by tests
}
return errs, nil

Check warning on line 48 in pkg/engine/assert/parse.go

View check run for this annotation

Codecov / codecov/patch

pkg/engine/assert/parse.go#L48

Added line #L48 was not covered by tests
}
for k, v := range n {
projection, err := project(ctx, k, value, bindings, opts...)
if err != nil {
Expand Down
Loading