Skip to content

Commit

Permalink
Merge pull request #627 from sergenyalcin/handle-nil-value-paved
Browse files Browse the repository at this point in the history
Add a nil case to the expandWildcards function
  • Loading branch information
turkenh committed Dec 13, 2023
2 parents 8d14356 + 4e24aae commit 0b37953
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/fieldpath/paved.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ func expandWildcards(data any, segments Segments) ([]Segments, error) { //nolint
}
res = append(res, r...)
}
case nil:
return nil, errNotFound{errors.Errorf("wildcard field %q is not found in the path", segments[:i])}
default:
return nil, errors.Errorf("%q: unexpected wildcard usage", segments[:i])
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/fieldpath/paved_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,14 @@ func TestExpandWildcards(t *testing.T) {
err: errors.Wrap(errors.New("unexpected ']' at position 5"), "cannot parse path \"spec[]\""),
},
},
"NilValue": {
reason: "Requesting a wildcard for an object that has nil value",
path: "spec.containers[*].name",
data: []byte(`{"spec":{"containers": null}}`),
want: want{
err: errors.Wrapf(errNotFound{errors.Errorf("wildcard field %q is not found in the path", "spec.containers")}, "cannot expand wildcards for segments: %q", "spec.containers[*].name"),
},
},
}

for name, tc := range cases {
Expand Down

0 comments on commit 0b37953

Please sign in to comment.