diff --git a/LICENSE b/LICENSE index 0eb9b72..382d7de 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ Copyright (c) 2014, Evan Phoenix + 2018, Google LLC All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/patch.go b/patch.go index de70dbc..42cf867 100644 --- a/patch.go +++ b/patch.go @@ -104,6 +104,10 @@ func (n *lazyNode) compact() []byte { } func (n *lazyNode) tryDoc() bool { + if n.raw == nil { + return false + } + err := json.Unmarshal(*n.raw, &n.doc) if err != nil { @@ -115,6 +119,10 @@ func (n *lazyNode) tryDoc() bool { } func (n *lazyNode) tryAry() bool { + if n.raw == nil { + return false + } + err := json.Unmarshal(*n.raw, &n.ary) if err != nil { diff --git a/patch_test.go b/patch_test.go index 40ff5af..9b441c7 100644 --- a/patch_test.go +++ b/patch_test.go @@ -314,6 +314,18 @@ var TestCases = []TestCase{ true, "", }, + { + `{ "foo": {} }`, + `[ { "op": "test", "path": "/foo", "value": null } ]`, + false, + "/foo", + }, + { + `{ "foo": [] }`, + `[ { "op": "test", "path": "/foo", "value": null } ]`, + false, + "/foo", + }, { `{ "baz/foo": "qux" }`, `[ { "op": "test", "path": "/baz~1foo", "value": "qux"} ]`,