Skip to content
Closed
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
13 changes: 5 additions & 8 deletions patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,14 @@ func equalValue(x, y Value) bool {
// * It fails to precisely compare integers beyond ±2⁵³.
// * It cannot handle values greater than ±math.MaxFloat64.
// * Comparison of objects with duplicate names has undefined behavior.
unmarshal := func(v Value) (vi interface{}) {
unmarshal := func(v Value) (vi interface{}, ok bool) {
v = v.Clone()
v.Standardize()
if json.Unmarshal(v.Pack(), &vi) != nil {
return nil
}
return vi
return vi, json.Unmarshal(v.Pack(), &vi) == nil
}
vx := unmarshal(x)
vy := unmarshal(y)
return reflect.DeepEqual(vx, vy) && vx != nil && vy != nil
vx, okx := unmarshal(x)
vy, oky := unmarshal(y)
return okx && oky && reflect.DeepEqual(vx, vy)
}

func (obj *Object) getAt(i int) ValueTrimmed {
Expand Down
8 changes: 8 additions & 0 deletions patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ var testdataPatch = []struct {
in: `{"fizz":["buzz","wuzz"],"fizzy":"wizzy"}`,
patch: `[{ "op": "test", "path": "/noexist", "value": null }]`,
wantErr: errors.New(`hujson: patch operation 0: value not found`),
}, {
in: `{"a":null}`,
patch: `[{ "op": "test", "path": "/a", "value": null }]`,
want: `{"a":null}`,
}, {
in: `{"a":null}`,
patch: `[{ "op": "test", "path": "/a", "value": 0 }]`,
wantErr: errors.New(`hujson: patch operation 0: values differ at "/a"`),
}, {
in: `{}`,
patch: `[{`,
Expand Down