mirror of
https://github.com/DaveGamble/cJSON.git
synced 2024-12-26 21:04:24 +08:00
json patch: adding to a subfield of a non-object now fails as expected
This commit is contained in:
parent
6f264b5d0c
commit
d26a42af8d
@ -988,6 +988,12 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
|
|||||||
cJSON_AddItemToObject(parent, (char*)child_pointer, value);
|
cJSON_AddItemToObject(parent, (char*)child_pointer, value);
|
||||||
value = NULL;
|
value = NULL;
|
||||||
}
|
}
|
||||||
|
else /* parent is not an object */
|
||||||
|
{
|
||||||
|
/* Couldn't find object to add to. */
|
||||||
|
status = 9;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (value != NULL)
|
if (value != NULL)
|
||||||
|
@ -80,5 +80,12 @@
|
|||||||
"doc": { "foo": ["bar"] },
|
"doc": { "foo": ["bar"] },
|
||||||
"patch": [ { "op": "add", "path": "/foo/-", "value": ["abc", "def"] }],
|
"patch": [ { "op": "add", "path": "/foo/-", "value": ["abc", "def"] }],
|
||||||
"expected": {"foo": ["bar", ["abc", "def"]] }
|
"expected": {"foo": ["bar", ["abc", "def"]] }
|
||||||
}
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"comment": "15",
|
||||||
|
"doc": {"foo": {"bar": 1}},
|
||||||
|
"patch": [{"op": "add", "path": "/foo/bar/baz", "value": "5"}],
|
||||||
|
"error": "attempting to add to subfield of non-object"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user