Skip to content

Commit

Permalink
identityref REVERT canonical value in JSON format with prefix
Browse files Browse the repository at this point in the history
Do not use the standard JSON format as caonical
value and always print the prefix like before.

Refs #2090
  • Loading branch information
michalvasko committed Sep 15, 2023
1 parent d3b351a commit 7d603c9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/plugins_types/identityref.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* @file identityref.c
* @author Radek Krejci <[email protected]>
* @author Michal Vasko <[email protected]>
* @brief Built-in identityref type plugin.
*
* Copyright (c) 2019-2021 CESNET, z.s.p.o.
* Copyright (c) 2019-2023 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
Expand Down Expand Up @@ -277,9 +278,12 @@ lyplg_type_store_identityref(const struct ly_ctx *ctx, const struct lysc_type *t
LY_CHECK_GOTO(ret, cleanup);
}
} else {
/* JSON format is the canonical one */
ret = identityref_ident2str(ident, LY_VALUE_JSON, ctx_node ? ctx_node->module : NULL, &canon, NULL);
LY_CHECK_GOTO(ret, cleanup);
/* JSON format with prefix is the canonical one */
if (asprintf(&canon, "%s:%s", ident->module->name, ident->name) == -1) {
LOGMEM(ctx);
ret = LY_EMEM;
goto cleanup;
}

ret = lydict_insert_zc(ctx, canon, &storage->_canonical);
LY_CHECK_GOTO(ret, cleanup);
Expand Down Expand Up @@ -315,7 +319,7 @@ lyplg_type_print_identityref(const struct ly_ctx *UNUSED(ctx), const struct lyd_
{
char *ret;

if ((format == LY_VALUE_CANON) || (format == LY_VALUE_JSON) || (format == LY_VALUE_LYB)) {
if (format == LY_VALUE_CANON) {
if (dynamic) {
*dynamic = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/utests/types/identityref.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test_data_xml(void **state)
/* local ident, XML/JSON print */
data = "<l1 xmlns=\"urn:tests:defs\">ident1</l1>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
CHECK_LYD_NODE_TERM((struct lyd_node_term *)tree, 0, 0, 0, 0, 1, IDENT, "ident1", "ident1");
CHECK_LYD_NODE_TERM((struct lyd_node_term *)tree, 0, 0, 0, 0, 1, IDENT, "defs:ident1", "ident1");
CHECK_LYD_STRING_PARAM(tree, data, LYD_XML, LYD_PRINT_SHRINK);
CHECK_LYD_STRING_PARAM(tree, "{\"defs:l1\":\"ident1\"}", LYD_JSON, LYD_PRINT_SHRINK);
lyd_free_all(tree);
Expand Down
2 changes: 1 addition & 1 deletion tests/utests/types/instanceid.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ test_data_xml(void **state)
"<list-ident xmlns=\"urn:tests:defs\"><id xmlns:b=\"urn:tests:defs\">b:ident-der2</id>"
"<value>y</value></list-ident>",
"defs", "xmlns:a=\"urn:tests:defs\"", "a:l1", "/a:list-ident[a:id='a:ident-der1']/a:value",
INST, "/defs:list-ident[id='ident-der1']/value", val5);
INST, "/defs:list-ident[id='defs:ident-der1']/value", val5);

TEST_SUCCESS_XML2("<list2 xmlns=\"urn:tests:defs\"><id>defs:xxx</id><id2>x</id2></list2>"
"<list2 xmlns=\"urn:tests:defs\"><id>a:xxx</id><id2>y</id2></list2>",
Expand Down
2 changes: 1 addition & 1 deletion tests/utests/types/union.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test_data_xml(void **state)
"defs", "", "un1", "2", UNION, "2", STRING, "2");

TEST_SUCCESS_XML2("<int8 xmlns=\"urn:tests:defs\">10</int8>",
"defs", "xmlns:x=\"urn:tests:defs\"", "un1", "x:ident2", UNION, "ident2", IDENT, "ident2", "ident2");
"defs", "xmlns:x=\"urn:tests:defs\"", "un1", "x:ident2", UNION, "defs:ident2", IDENT, "defs:ident2", "ident2");

TEST_SUCCESS_XML2("<int8 xmlns=\"urn:tests:defs\">10</int8>",
"defs", "xmlns:x=\"urn:tests:defs\"", "un1", "x:ident55", UNION, "x:ident55", STRING, "x:ident55");
Expand Down

0 comments on commit 7d603c9

Please sign in to comment.