🚑 fix for #894

- Implemented "copy" in terms of "add".
- Added check for JSON Pointer array indices to make sure the complete reference token was processed.
- Added test suite from https://github.com/json-patch/json-patch-tests
This commit is contained in:
Niels Lohmann 2017-12-28 13:52:23 +01:00
parent 3113a52a7d
commit 3b3b6e8e69
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
6 changed files with 853 additions and 18 deletions

View file

@ -1322,4 +1322,32 @@ TEST_CASE("regression tests")
j = ar;
ar = j;
}
SECTION("issue #894 - invalid RFC6902 copy operation succeeds")
{
auto model = R"({
"one": {
"two": {
"three": "hello",
"four": 42
}
}
})"_json;
CHECK_THROWS_AS(model.patch(R"([{"op": "move",
"from": "/one/two/three",
"path": "/a/b/c"}])"_json), json::out_of_range);
CHECK_THROWS_WITH(model.patch(R"([{"op": "move",
"from": "/one/two/three",
"path": "/a/b/c"}])"_json),
"[json.exception.out_of_range.403] key 'a' not found");
CHECK_THROWS_AS(model.patch(R"([{"op": "copy",
"from": "/one/two/three",
"path": "/a/b/c"}])"_json), json::out_of_range);
CHECK_THROWS_WITH(model.patch(R"([{"op": "copy",
"from": "/one/two/three",
"path": "/a/b/c"}])"_json),
"[json.exception.out_of_range.403] key 'a' not found");
}
}