Skip to content

Commit

Permalink
parser json UPDATE allowing JSON 'null' value for inner nodes (CESNET…
Browse files Browse the repository at this point in the history
  • Loading branch information
steweg authored Apr 5, 2024
1 parent f6ad0b6 commit 68f6eaf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/parser_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1491,11 +1491,11 @@ lydjson_parse_instance(struct lyd_json_ctx *lydctx, struct lyd_node *parent, str
r = lydjson_data_check_opaq(lydctx, snode, &type_hints);
if (r == LY_SUCCESS) {
assert(snode->nodetype & (LYD_NODE_TERM | LYD_NODE_INNER | LYD_NODE_ANY));
if (snode->nodetype & LYD_NODE_TERM) {
if ((lydctx->parse_opts & LYD_PARSE_JSON_NULL) && (*status == LYJSON_NULL)) {
/* do not do anything if value is JSON 'null' */
goto cleanup;
} else if ((*status != LYJSON_ARRAY) && (*status != LYJSON_NUMBER) && (*status != LYJSON_STRING) &&
if ((lydctx->parse_opts & LYD_PARSE_JSON_NULL) && (*status == LYJSON_NULL)) {
/* do not do anything if value is JSON 'null' */
goto cleanup;
} else if (snode->nodetype & LYD_NODE_TERM) {
if ((*status != LYJSON_ARRAY) && (*status != LYJSON_NUMBER) && (*status != LYJSON_STRING) &&
(*status != LYJSON_FALSE) && (*status != LYJSON_TRUE) && (*status != LYJSON_NULL)) {
rc = LY_ENOT;
goto cleanup;
Expand All @@ -1522,10 +1522,6 @@ lydjson_parse_instance(struct lyd_json_ctx *lydctx, struct lyd_node *parent, str
r = lydjson_parse_instance_inner(lydctx, snode, ext, status, node);
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);
} else {
if ((lydctx->parse_opts & LYD_PARSE_JSON_NULL) && (*status == LYJSON_NULL)) {
/* do not do anything if value is JSON 'null' */
goto cleanup;
}
/* create any node */
r = lydjson_parse_any(lydctx, snode, ext, status, node);
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);
Expand Down
5 changes: 5 additions & 0 deletions tests/utests/data/test_parser_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,11 @@ test_container(void **state)
CHECK_PARSE_LYD("{\"a:unknown\":{\"a\":\"val\",\"b\":5}}", 0, LYD_VALIDATE_PRESENT, tree);
CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{}");
lyd_free_all(tree);

data = "{\"a:c\": null}";
PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, "Expecting JSON name/object but container \"c\" is represented in input data as name/null.", NULL, 1);
CHECK_PARSE_LYD(data, LYD_PARSE_JSON_NULL, LYD_VALIDATE_PRESENT, tree);
assert_null(tree);
}

static void
Expand Down

0 comments on commit 68f6eaf

Please sign in to comment.