Skip to content

Commit a07288a

Browse files
committed
parser json BUGFIX inner node opaque parsing
Fixes #2503
1 parent e1486db commit a07288a

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

src/parser_json.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,6 @@ lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *sno
517517

518518
assert(snode);
519519

520-
if (!(snode->nodetype & (LYD_NODE_TERM | LYS_LIST))) {
521-
/* can always be parsed as a data node if we have the schema node */
522-
return LY_SUCCESS;
523-
}
524-
525520
/* backup parser */
526521
lyjson_ctx_backup(jsonctx);
527522
status = lyjson_ctx_status(jsonctx);
@@ -553,6 +548,15 @@ lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *sno
553548
ret = LY_ENOT;
554549
}
555550
break;
551+
case LYS_CONTAINER:
552+
case LYS_RPC:
553+
case LYS_ACTION:
554+
case LYS_NOTIF:
555+
/* check the status only */
556+
if (status != LYJSON_OBJECT) {
557+
ret = LY_ENOT;
558+
}
559+
break;
556560
}
557561
} else if (snode->nodetype & LYD_NODE_TERM) {
558562
ret = lydjson_value_type_hint(lydctx, snode, &status, type_hint_p);

tests/utests/extensions/test_structure.c

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Michal Vasko <mvasko@cesnet.cz>
44
* @brief unit tests for structure extensions support
55
*
6-
* Copyright (c) 2022 - 2025 CESNET, z.s.p.o.
6+
* Copyright (c) 2022 - 2026 CESNET, z.s.p.o.
77
*
88
* This source code is licensed under BSD 3-Clause License (the "License").
99
* You may not use this file except in compliance with the License.
@@ -339,6 +339,62 @@ test_parse(void **state)
339339
LYD_PARSE_STRICT | LYD_PARSE_ANYDATA_STRICT, LYD_VALIDATE_PRESENT, &tree));
340340
CHECK_LOG_CTX("Node \"l2\" not found as a child of \"cont\" node.",
341341
"/a:struct/x/struct/x/any/c:cont", 1);
342+
343+
/* patch */
344+
ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG);
345+
assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-yang-patch", NULL, NULL));
346+
yang = "module example {yang-version 1.1;namespace \"http://example.tld/example\";prefix ex;"
347+
" container a {"
348+
" container b {"
349+
" container c {"
350+
" leaf enabled {"
351+
" type boolean;"
352+
" default true;"
353+
" }"
354+
" leaf blower {"
355+
" type string;"
356+
" }"
357+
" }"
358+
" }"
359+
" container b1 { }"
360+
" leaf something { type string; }"
361+
" }"
362+
" container two-leafs {"
363+
" leaf a { type string; }"
364+
" leaf b { type string; }"
365+
" }"
366+
"}";
367+
UTEST_ADD_MODULE(yang, LYS_IN_YANG, NULL, NULL);
368+
369+
json =
370+
"{\n"
371+
" \"ietf-yang-patch:yang-patch\": {\n"
372+
" \"patch-id\": \"patch\",\n"
373+
" \"edit\": [\n"
374+
" {\n"
375+
" \"edit-id\": \"edit\",\n"
376+
" \"operation\": \"replace\",\n"
377+
" \"target\": \"/example:a\",\n"
378+
" \"value\": {\n"
379+
" \"example:a\": \"aaa\"\n"
380+
" }\n"
381+
" },\n"
382+
" {\n"
383+
" \"edit-id\": \"edit\",\n"
384+
" \"operation\": \"replace\",\n"
385+
" \"target\": \"/example:b\",\n"
386+
" \"value\": {\n"
387+
" \"example:b\": \"bbb\"\n"
388+
" }\n"
389+
" }\n"
390+
" ]\n"
391+
" }\n"
392+
"}\n";
393+
assert_int_equal(LY_SUCCESS, ly_in_new_memory(json, &UTEST_IN));
394+
assert_int_equal(LY_SUCCESS, lyd_parse_data(UTEST_LYCTX, NULL, UTEST_IN, LYD_JSON, LYD_PARSE_STRICT | LYD_PARSE_ONLY,
395+
0, &tree));
396+
CHECK_LYD_STRING_PARAM(tree, json, LYD_JSON, LYD_PRINT_SIBLINGS);
397+
lyd_free_all(tree);
342398
}
343399

344400
static void

0 commit comments

Comments
 (0)