Skip to content

Commit

Permalink
fix: disallow null in empty object assertion
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly committed Jul 21, 2024
1 parent c760bee commit 8ff9c96
Showing 1 changed file with 7 additions and 0 deletions.
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 @@ type mapNode map[any]Assertion

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

0 comments on commit 8ff9c96

Please sign in to comment.