mirror of
https://github.com/json-c/json-c.git
synced 2026-11-05 21:20:16 +08:00
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.
52 lines
1.8 KiB
C
52 lines
1.8 KiB
C
/*
|
|
* Copyright (c) 2023 Eric Hawicz
|
|
*
|
|
* This library is free software; you can redistribute it and/or modify
|
|
* it under the terms of the MIT license. See COPYING for details.
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* @brief Do not use, json-c internal, may be changed or removed at any time.
|
|
*/
|
|
#ifndef _json_pointer_private_h_
|
|
#define _json_pointer_private_h_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
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: 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;
|
|
};
|
|
|
|
int json_pointer_get_internal(struct json_object *obj, const char *path,
|
|
struct json_pointer_get_result *res);
|
|
|
|
// replaced by json_pointer_set_cb
|
|
// typedef int(*json_pointer_array_set_cb)(json_object *parent, size_t idx,
|
|
// json_object *value, void *priv);
|
|
typedef int(*json_pointer_set_cb)(json_object *parent, const char *key, size_t idx,
|
|
json_object *value, void *priv);
|
|
|
|
// replaced by json_pointer_set_with_cb
|
|
// int json_pointer_set_with_array_cb(struct json_object **obj, const char *path,
|
|
// struct json_object *value,
|
|
// json_pointer_array_set_cb array_set_cb, void *priv);
|
|
int json_pointer_set_with_cb(struct json_object **obj, const char *path,
|
|
struct json_object *value,
|
|
json_pointer_set_cb set_cb, int cb_handles_obj, void *priv);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|