Skip to content

Commit 284d743

Browse files
committed
tree data UPDATE new path support for string values in anyxml
1 parent 797d9be commit 284d743

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/tree_data_new.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ lyd_create_any(const struct lysc_node *schema, const struct lyd_node *child, con
273273
}
274274
} else {
275275
/* anyxml */
276+
if (hints & 0x0FFF) {
277+
/* any LYD_VALHINT_* */
278+
try_parse = 0;
279+
}
276280
if (value && try_parse) {
277281
/* try to parse as a data tree */
278282
r = lyd_create_any_datatree(schema->module->ctx, value, 0, &tree);
@@ -297,10 +301,10 @@ lyd_create_any(const struct lysc_node *schema, const struct lyd_node *child, con
297301
} else if (value) {
298302
LY_CHECK_GOTO(rc = lydict_insert_zc(schema->module->ctx, (void *)value, &any->value), cleanup);
299303
}
304+
any->hints = hints;
300305
} else {
301-
LY_CHECK_GOTO(rc = lyd_any_copy_value(&any->node, child, value, 0), cleanup);
306+
LY_CHECK_GOTO(rc = lyd_any_copy_value(&any->node, child, value, hints), cleanup);
302307
}
303-
any->hints = hints;
304308
lyd_hash(&any->node);
305309

306310
cleanup:
@@ -335,7 +339,7 @@ lyd_any_copy_value(struct lyd_node *trg, const struct lyd_node *child, const cha
335339
return LY_SUCCESS;
336340
}
337341

338-
if (value) {
342+
if (value && ((trg->schema->nodetype == LYS_ANYDATA) || !(hints & 0x0FFF))) {
339343
/* try to parse as a data tree */
340344
if (!lyd_create_any_datatree(LYD_CTX(trg), value, 0, &node)) {
341345
/* use the parsed data tree */

tests/utests/data/test_new.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,21 @@ test_path(void **state)
506506
"}\n");
507507
free(str);
508508
lyd_free_siblings(root);
509+
510+
ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:anyx", "<a/><b/><c/>", 0, LYD_VALHINT_STRING, 0, &root, NULL);
511+
assert_int_equal(ret, LY_SUCCESS);
512+
assert_non_null(root);
513+
lyd_print_mem(&str, root, LYD_XML, LYD_PRINT_SIBLINGS);
514+
assert_string_equal(str,
515+
"<anyx xmlns=\"urn:tests:a\">&lt;a/&gt;&lt;b/&gt;&lt;c/&gt;</anyx>\n");
516+
free(str);
517+
lyd_print_mem(&str, root, LYD_JSON, LYD_PRINT_SIBLINGS);
518+
assert_string_equal(str,
519+
"{\n"
520+
" \"a:anyx\": \"<a/><b/><c/>\"\n"
521+
"}\n");
522+
free(str);
523+
lyd_free_siblings(root);
509524
}
510525

511526
static void

0 commit comments

Comments
 (0)