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:
fhgffy authored and Eric Hawicz committed 2026-10-25 18:19:07 -04:00
1 parent e77ca4fb3d
commit 86fe287188
4 files changed
+26 -3

No files matched your search

+2 -1
View File
@@ -20,7 +20,8 @@ struct json_pointer_get_result {
struct json_object *parent;
struct json_object *obj;
// The key of the found object; only valid when parent is json_type_object
// Caution: re-uses tail end of the `path` argument to json_pointer_get_internal
// Caution: points at the key stored in `parent`, so it is only valid
// as long as that member exists
const char *key_in_parent;
// the index of the found object; only valid when parent is json_type_array
uint32_t index_in_parent;