cJSON

mirror of Dave's cJSON
git clone git://git.thc420.xyz/cJSON
Log | Files | Refs | README | LICENSE

commit 8abf1107500d516407ecfa916aca7ebc64c7c31e
parent 6f264b5d0c7a494934ca418634c47365f8b87e5a
Author: Max Bruckner <max@maxbruckner.de>
Date:   Thu, 22 Mar 2018 20:00:24 +0100

Merge pull request #251 from bobkocisko/master

json patch: adding to a subfield of a non-object now fails as expected
Diffstat:
McJSON_Utils.c | 6++++++
Mtests/json-patch-tests/cjson-utils-tests.json | 9++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/cJSON_Utils.c b/cJSON_Utils.c @@ -988,6 +988,12 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_ cJSON_AddItemToObject(parent, (char*)child_pointer, value); value = NULL; } + else /* parent is not an object */ + { + /* Couldn't find object to add to. */ + status = 9; + goto cleanup; + } cleanup: if (value != NULL) diff --git a/tests/json-patch-tests/cjson-utils-tests.json b/tests/json-patch-tests/cjson-utils-tests.json @@ -80,5 +80,12 @@ "doc": { "foo": ["bar"] }, "patch": [ { "op": "add", "path": "/foo/-", "value": ["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" + } ]