From 12ca3d90aecb652de29ed1680e0a5b3d49a12df4 Mon Sep 17 00:00:00 2001
From: Zachary Marois
It is an error if no value exists at the given path.
+ *It is an error if no value exists at the given path and there is an expected value to test equality against.
* *Also note that equality as defined by JSON Patch is exactly the same as it * is defined by JSON Schema itself. As such, this operation reuses {@link @@ -57,10 +57,11 @@ public JsonNode apply(final JsonNode node) throws JsonPatchException { final JsonNode tested = path.path(node); - if (tested.isMissingNode()) + + if (tested.isMissingNode() && !value.isNull()) throw new JsonPatchException(BUNDLE.getMessage( "jsonPatch.noSuchPath")); - if (!EQUIVALENCE.equivalent(tested, value)) + if (!(tested.isMissingNode() && value.isNull()) && !EQUIVALENCE.equivalent(tested, value)) throw new JsonPatchException(BUNDLE.getMessage( "jsonPatch.valueTestFailure")); return node.deepCopy(); diff --git a/src/test/resources/jsonpatch/test.json b/src/test/resources/jsonpatch/test.json index d80f3c60..6ce1d210 100644 --- a/src/test/resources/jsonpatch/test.json +++ b/src/test/resources/jsonpatch/test.json @@ -14,6 +14,11 @@ "op": { "op": "test", "path": "/x", "value": -30.000 }, "node": { "x": -29.020 }, "message": "jsonPatch.valueTestFailure" + }, + { + "op": { "op": "test", "path": "/a/1", "value": null }, + "node": { "a": [ null, "hello", "world" ] }, + "message": "jsonPatch.valueTestFailure" } ], "ops": [ @@ -26,6 +31,11 @@ "op": { "op": "test", "path": "/a/1", "value": "hello" }, "node": { "a": [ null, "hello", "world" ] }, "expected": { "a": [ null, "hello", "world" ] } + }, + { + "op": { "op": "test", "path": "/x", "value": null }, + "node": 1.00, + "expected": 1.00 } ] -} \ No newline at end of file +}