mirror of
https://github.com/json-c/json-c.git
synced 2026-11-06 05:30:17 +08:00
json_patch: remove members whose names contain '/' or '~'
json_pointer_get_internal() decodes the last reference token in a private copy of the path, then pointed key_in_parent at the same offset in the caller's path, where the token is still escaped. For a path like "/a~1b" that gave "a~1b" instead of "a/b", so json_patch's remove, and the remove step of move, called json_object_object_del() with a key that doesn't exist. Nothing was removed and the patch still reported success; a move left the source member in place. Point key_in_parent at the key as it is stored in the parent object instead, which is always the decoded name. Added remove and move cases with escaped member names to json_patch_tests.json and refreshed test_json_patch.expected.
This commit is contained in:
1 parent
e77ca4fb3d
commit
86fe287188
4 files changed
+26
-3
No files matched your search
@@ -380,6 +380,17 @@
|
||||
"patch": [{"op": "copy", "from": "/aa", "path": "/aab"}],
|
||||
"expected": {"aa": 1, "aab": 1} },
|
||||
|
||||
{ "comment": "Remove members whose names need escaping",
|
||||
"doc": {"a/b": 1, "m~n": 2, "c": 3},
|
||||
"patch": [{"op": "remove", "path": "/a~1b"},
|
||||
{"op": "remove", "path": "/m~0n"}],
|
||||
"expected": {"c": 3} },
|
||||
|
||||
{ "comment": "Move from a member whose name needs escaping",
|
||||
"doc": {"a/b": 1},
|
||||
"patch": [{"op": "move", "from": "/a~1b", "path": "/c"}],
|
||||
"expected": {"c": 1} },
|
||||
|
||||
{ "doc": {"foo": 1, "baz": [{"qux": "hello"}]},
|
||||
"patch": [{"op": "move", "from": "/foo", "path": "/bar"}],
|
||||
"expected": {"baz": [{"qux": "hello"}], "bar": 1} },
|
||||
|
||||
@@ -102,6 +102,8 @@ Testing '(null)', doc '{ "foo": [ "bar", "baz" ], "": 0, "a\/b": 1, "c%d": 2, "e
|
||||
Testing 'Move to same location has no effect', doc '{ "foo": 1 }' patch '[ { "op": "move", "from": "\/foo", "path": "\/foo" } ]' : OK
|
||||
Testing 'Move between sibling keys sharing a name prefix is not a parent/child move', doc '{ "aa": 1, "aab": 2 }' patch '[ { "op": "move", "from": "\/aa", "path": "\/aab" } ]' : OK
|
||||
Testing 'Copy between sibling keys sharing a name prefix is not a parent/child move', doc '{ "aa": 1, "aab": 2 }' patch '[ { "op": "copy", "from": "\/aa", "path": "\/aab" } ]' : OK
|
||||
Testing 'Remove members whose names need escaping', doc '{ "a\/b": 1, "m~n": 2, "c": 3 }' patch '[ { "op": "remove", "path": "\/a~1b" }, { "op": "remove", "path": "\/m~0n" } ]' : OK
|
||||
Testing 'Move from a member whose name needs escaping', doc '{ "a\/b": 1 }' patch '[ { "op": "move", "from": "\/a~1b", "path": "\/c" } ]' : OK
|
||||
Testing '(null)', doc '{ "foo": 1, "baz": [ { "qux": "hello" } ] }' patch '[ { "op": "move", "from": "\/foo", "path": "\/bar" } ]' : OK
|
||||
Testing '(null)', doc '{ "baz": [ { "qux": "hello" } ], "bar": 1 }' patch '[ { "op": "move", "from": "\/baz\/0\/qux", "path": "\/baz\/1" } ]' : OK
|
||||
Testing '(null)', doc '{ "baz": [ { "qux": "hello" } ], "bar": 1 }' patch '[ { "op": "copy", "from": "\/baz\/0", "path": "\/boo" } ]' : OK
|
||||
|
||||
Reference in new issue
Block a user