Skip to content
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
8 changes: 8 additions & 0 deletions typed/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (w *removingWalker) doList(t *schema.List) (errs ValidationErrors) {
defer w.allocator.Free(l)
// If list is null or empty just return
if l == nil || l.Length() == 0 {
// For extraction, we just return the value as is (which is nil or empty). For extraction the difference matters.
if w.shouldExtract {
w.out = w.value.Unstructured()
}
return nil
}

Expand Down Expand Up @@ -113,6 +117,10 @@ func (w *removingWalker) doMap(t *schema.Map) ValidationErrors {
}
// If map is null or empty just return
if m == nil || m.Empty() {
// For extraction, we just return the value as is (which is nil or empty). For extraction the difference matters.
if w.shouldExtract {
w.out = w.value.Unstructured()
}
return nil
}

Expand Down
32 changes: 32 additions & 0 deletions typed/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,38 @@ var removeCases = []removeTestCase{{
),
`{"mapOfMapsRecursive":{"a":{"b":null}}}`,
`{"mapOfMapsRecursive": {"a":{"b":{"c":null}}}}`,
}, {
// empty list
`{"listOfLists": []}`,
_NS(
_P("listOfLists"),
),
``,
`{"listOfLists": []}`,
}, {
// null list
`{"listOfLists": null}`,
_NS(
_P("listOfLists"),
),
``,
`{"listOfLists": null}`,
}, {
// empty map
`{"mapOfMaps": {}}`,
_NS(
_P("mapOfMaps"),
),
``,
`{"mapOfMaps": {}}`,
}, {
// nil map
`{"mapOfMaps": null}`,
_NS(
_P("mapOfMaps"),
),
``,
`{"mapOfMaps": null}`,
}},
}}

Expand Down