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 ex… #41

Open
wants to merge 1 commit 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
7 changes: 4 additions & 3 deletions src/main/java/com/github/fge/jsonpatch/TestOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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 @@ -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();
Expand Down
12 changes: 11 additions & 1 deletion src/test/resources/jsonpatch/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -26,6 +31,11 @@
"op": { "op": "test", "path": "/a/1", "value": "hello" },
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this newline is very important for windows 98 json parsers

"node": { "a": [ null, "hello", "world" ] },
"expected": { "a": [ null, "hello", "world" ] }
},
{
"op": { "op": "test", "path": "/x", "value": null },
"node": 1.00,
"expected": 1.00
}
]
}
}