Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling testing for a pointer that references a nonexistent value #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* to test ({@code path}) and the value to test equality against ({@code
* value}).</p>
*
* <p>It is an error if no value exists at the given path.</p>
* <p>It is an error if no value exists at the given path and there is an expected value to test equality against.</p>
*
* <p>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
Expand All @@ -61,10 +61,10 @@ 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();
Expand Down
14 changes: 13 additions & 1 deletion src/test/resources/jsonpatch/standard/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
"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": [
{
Expand All @@ -26,6 +32,12 @@
"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
}

]
}
}