Merge pull request #251 from bobkocisko/master

json patch: adding to a subfield of a non-object now fails as expected
This commit is contained in:
Max Bruckner 2018-03-22 20:00:24 +01:00 committed by GitHub
commit 8abf110750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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)

View File

@ -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"
}
]