Skip to content

Commit

Permalink
Represent JSON merge nulls as voids internally.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephburnett committed Jun 20, 2022
1 parent 94b98dd commit 3742455
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/diff_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ func readMergeInto(d Diff, p path, n JsonNode) Diff {
d = readMergeInto(d, append(p.clone(), jsonString(k)), v)
}
default:
if isNull(n) {
n = voidNode{}
}
return append(d, DiffElement{
Path: p.clone(),
NewValues: []JsonNode{n},
Expand Down
5 changes: 5 additions & 0 deletions lib/diff_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ func (d Diff) RenderMerge() (string, error) {
if len(e.Path) == 0 || !(jsonArray{jsonString(MERGE.string())}).Equals(e.Path[0]) {
return "", fmt.Errorf("Diff must be composed entirely of paths with merge metadata to be rendered as a merge patch.")
}
for i := range e.NewValues {
if isVoid(e.NewValues[i]) {
e.NewValues[i] = jsonNull{}
}
}
}
mergePatch, err := voidNode{}.Patch(d)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions lib/patch_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ func patch(
if !isVoid(oldValue) {
return patchErrMergeWithOldValue(pathBehind, oldValue)
}
if isNull(newValue) {
// Null deletes a node
return voidNode{}, nil
}
case strictPatchStrategy:
if !node.Equals(oldValue) {
return patchErrExpectValue(oldValue, node, pathBehind)
Expand Down

0 comments on commit 3742455

Please sign in to comment.