Skip to content

Commit b1ed7e5

Browse files
committed
JSON parser BUGFIX handling LYD_OPT_DATA_ADD_YANGLIB option on empty JSON data
1 parent a62a9d1 commit b1ed7e5

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/parser_json.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,9 @@ lyd_parse_json(struct ly_ctx *ctx, const char *data, int options, const struct l
12871287

12881288
/* no data (or whitespaces only) are fine */
12891289
if (!data[len]) {
1290+
if (options & LYD_OPT_DATA_ADD_YANGLIB) {
1291+
result = ly_ctx_info(ctx);
1292+
}
12901293
lyd_validate(&result, options, ctx);
12911294
return result;
12921295
}
@@ -1418,9 +1421,7 @@ lyd_parse_json(struct ly_ctx *ctx, const char *data, int options, const struct l
14181421

14191422
/* add missing ietf-yang-library if requested */
14201423
if (options & LYD_OPT_DATA_ADD_YANGLIB) {
1421-
if (!result) {
1422-
result = ly_ctx_info(ctx);
1423-
} else if (lyd_merge(result, ly_ctx_info(ctx), LYD_OPT_DESTRUCT | LYD_OPT_EXPLICIT)) {
1424+
if (lyd_merge(result, ly_ctx_info(ctx), LYD_OPT_DESTRUCT | LYD_OPT_EXPLICIT)) {
14241425
LOGERR(LY_EINT, "Adding ietf-yang-library data failed.");
14251426
goto error;
14261427
}

0 commit comments

Comments
 (0)