Skip to content

Commit 42c1e70

Browse files
committed
tree data UPDATE do not require context if available
New test included. Refs #3582
1 parent ce38b35 commit 42c1e70

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/tree_data.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,14 @@ LIBYANG_API_DEF LY_ERR
222222
lyd_parse_data(const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format,
223223
uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree)
224224
{
225-
LY_CHECK_ARG_RET(ctx, ctx, in, parent || tree, LY_EINVAL);
225+
LY_CHECK_ARG_RET(ctx, ctx || parent, in, parent || tree, LY_EINVAL);
226226
LY_CHECK_ARG_RET(ctx, !(parse_options & ~LYD_PARSE_OPTS_MASK), LY_EINVAL);
227227
LY_CHECK_ARG_RET(ctx, !(validate_options & ~LYD_VALIDATE_OPTS_MASK), LY_EINVAL);
228228

229+
if (!ctx) {
230+
ctx = LYD_CTX(parent);
231+
}
232+
229233
return lyd_parse(ctx, NULL, parent, tree, in, format, parse_options, validate_options, NULL);
230234
}
231235

tests/utests/data/test_parser_json.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,25 @@ test_metadata(void **state)
935935
CHECK_LOG_CTX("Invalid non-number-encoded int8 value \"value\".", "/a:c/x/@a:hint", 1);
936936
}
937937

938+
static void
939+
test_parent(void **state)
940+
{
941+
const char *data;
942+
struct lyd_node *tree;
943+
struct ly_in *in;
944+
945+
/* create the parent */
946+
assert_int_equal(LY_SUCCESS, lyd_new_path(NULL, UTEST_LYCTX, "/a:l1[a='vala'][b='valb'][c='25']", NULL, 0, &tree));
947+
948+
/* parse nested data */
949+
data = "{\"cont\":{\"e\":false}}";
950+
assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
951+
assert_int_equal(LY_SUCCESS, lyd_parse_data(NULL, tree, in, LYD_JSON, 0, LYD_VALIDATE_PRESENT, NULL));
952+
953+
ly_in_free(in, 0);
954+
lyd_free_tree(tree);
955+
}
956+
938957
int
939958
main(void)
940959
{
@@ -954,6 +973,7 @@ main(void)
954973
UTEST(test_restconf_notification, setup),
955974
UTEST(test_restconf_reply, setup),
956975
UTEST(test_metadata, setup),
976+
UTEST(test_parent, setup),
957977
};
958978

959979
return cmocka_run_group_tests(tests, NULL, NULL);

0 commit comments

Comments
 (0)