mirror of
https://github.com/json-c/json-c.git
synced 2026-09-07 08:36:50 +08:00
deep copy values in json_patch copy op to avoid aliasing and cycles
This commit is contained in:
@@ -535,6 +535,13 @@
|
||||
"doc": {"foo":"bar"},
|
||||
"patch": [{"op": "add", "path": "/FOO", "value": "BAR"}],
|
||||
"expected": {"foo": "bar", "FOO": "BAR"}
|
||||
},
|
||||
|
||||
{ "comment": "copy must duplicate the value, not alias it, so no cycle can form",
|
||||
"doc": {"a": {"p": {}}},
|
||||
"patch": [{"op": "copy", "from": "/a", "path": "/b"},
|
||||
{"op": "copy", "from": "/b", "path": "/a/p/x"}],
|
||||
"expected": {"a": {"p": {"x": {"p": {}}}}, "b": {"p": {}}}
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
@@ -156,3 +156,4 @@ Testing 'Removing deep nonexistent path', doc '{ "foo": "bar" }' patch '[ { "op"
|
||||
Testing 'Removing nonexistent index', doc '[ "foo", "bar" ]' patch '[ { "op": "remove", "path": "\/2" } ]' : OK
|
||||
=> json_patch_apply failed as expected: ERRNO=ENOENT at patch idx 0: Did not find element referenced by path field
|
||||
Testing 'Patch with different capitalisation than doc', doc '{ "foo": "bar" }' patch '[ { "op": "add", "path": "\/FOO", "value": "BAR" } ]' : OK
|
||||
Testing 'copy must duplicate the value, not alias it, so no cycle can form', doc '{ "a": { "p": { } } }' patch '[ { "op": "copy", "from": "\/a", "path": "\/b" }, { "op": "copy", "from": "\/b", "path": "\/a\/p\/x" } ]' : OK
|
||||
|
||||
Reference in New Issue
Block a user