Skip to content

Commit 975e5bb

Browse files
committed
parser json BUGFIX opaque (leaf-)list parsing
1 parent 51f469b commit 975e5bb

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

src/parser_json.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,30 +1691,37 @@ lydjson_subtree_r(struct lyd_json_ctx *lydctx, struct lyd_node *parent, struct l
16911691
switch (snode->nodetype) {
16921692
case LYS_LEAFLIST:
16931693
case LYS_LIST:
1694-
LY_CHECK_GOTO(status != LYJSON_ARRAY, representation_error);
1694+
if (status == LYJSON_ARRAY) {
1695+
/* process all the values/objects */
1696+
do {
1697+
/* move into array/next value */
1698+
r = lyjson_ctx_next(lydctx->jsonctx, &status);
1699+
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
1700+
if (status == LYJSON_ARRAY_CLOSED) {
1701+
/* empty array, fine... */
1702+
break;
1703+
}
16951704

1696-
/* process all the values/objects */
1697-
do {
1698-
/* move into array/next value */
1699-
r = lyjson_ctx_next(lydctx->jsonctx, &status);
1700-
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
1701-
if (status == LYJSON_ARRAY_CLOSED) {
1702-
/* empty array, fine... */
1703-
break;
1704-
}
1705+
r = lydjson_parse_instance(lydctx, parent, first_p, snode, ext, name, name_len, prefix, prefix_len,
1706+
&status, &node);
1707+
if (r == LY_ENOT) {
1708+
goto representation_error;
1709+
}
1710+
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);
17051711

1712+
/* move after the item(s) */
1713+
r = lyjson_ctx_next(lydctx->jsonctx, &status);
1714+
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
1715+
} while (status == LYJSON_ARRAY_NEXT);
1716+
} else {
1717+
/* may still be an opaque node */
17061718
r = lydjson_parse_instance(lydctx, parent, first_p, snode, ext, name, name_len, prefix, prefix_len,
17071719
&status, &node);
17081720
if (r == LY_ENOT) {
17091721
goto representation_error;
17101722
}
17111723
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);
1712-
1713-
/* move after the item(s) */
1714-
r = lyjson_ctx_next(lydctx->jsonctx, &status);
1715-
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
1716-
} while (status == LYJSON_ARRAY_NEXT);
1717-
1724+
}
17181725
break;
17191726
case LYS_LEAF:
17201727
case LYS_CONTAINER:

0 commit comments

Comments
 (0)