tree schema UPDATE check for namespace collisions
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 1f9fd69..1116310 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -1646,6 +1646,15 @@
goto cleanup;
}
+ /* check whether there is not a namespace collision */
+ mod_dup = ly_ctx_get_module_latest_ns(ctx, mod->ns);
+ if (mod_dup && (mod_dup->revision == mod->revision)) {
+ LOGERR(ctx, LY_EINVAL, "Two different modules (\"%s\" and \"%s\") have the same namespace \"%s\".",
+ mod_dup->name, mod->name, mod->ns);
+ ret = LY_EINVAL;
+ goto cleanup;
+ }
+
switch (in->type) {
case LY_IN_FILEPATH:
/* check that name and revision match filename */
diff --git a/tests/utests/schema/test_parser_yang.c b/tests/utests/schema/test_parser_yang.c
index 6c18238..aea84c6 100644
--- a/tests/utests/schema/test_parser_yang.c
+++ b/tests/utests/schema/test_parser_yang.c
@@ -609,15 +609,15 @@
CHECK_LOG_CTX("Missing mandatory keyword \"namespace\" as a child of \"module\".", "Line number 1.");
mod = mod_renew(YCTX);
- in.current = " name {namespace urn:x;}";
+ in.current = " name {namespace urn:name;}";
assert_int_equal(LY_EVALID, parse_module(YCTX, mod));
- assert_string_equal("urn:x", mod->mod->ns);
+ assert_string_equal("urn:name", mod->mod->ns);
CHECK_LOG_CTX("Missing mandatory keyword \"prefix\" as a child of \"module\".", "Line number 1.");
mod = mod_renew(YCTX);
- in.current = " name {namespace urn:x;prefix \"x\";}";
+ in.current = " name {namespace urn:name;prefix \"n\";}";
assert_int_equal(LY_SUCCESS, parse_module(YCTX, mod));
- assert_string_equal("x", mod->mod->prefix);
+ assert_string_equal("n", mod->mod->prefix);
mod = mod_renew(YCTX);
#define SCHEMA_BEGINNING " name {yang-version 1.1;namespace urn:x;prefix \"x\";"
@@ -703,7 +703,7 @@
mod = mod_renew(YCTX);
LOG_LOCBACK(0, 0, 0, 1);
- in.current = "module name10 {yang-version 1.1;namespace urn:x;prefix \"x\";import zzz {prefix y;}import zzz {prefix z;}}";
+ in.current = "module name10 {yang-version 1.1;namespace urn:name10;prefix \"n10\";import zzz {prefix y;}import zzz {prefix z;}}";
assert_int_equal(lys_parse_mem(PARSER_CUR_PMOD(YCTX)->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_SUCCESS);
CHECK_LOG_CTX("Single revision of the module \"zzz\" imported twice.", NULL);
diff --git a/tests/utests/schema/test_schema_common.c b/tests/utests/schema/test_schema_common.c
index 97af0fb..f66deb2 100644
--- a/tests/utests/schema/test_schema_common.c
+++ b/tests/utests/schema/test_schema_common.c
@@ -599,8 +599,8 @@
/* config -> state leafref */
str = "module b {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:b;\n"
+ " prefix b;\n"
" container cont {\n"
" config false;\n"
" leaf l {\n"
@@ -621,8 +621,8 @@
/* config -> state must */
str = "module b {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:b;\n"
+ " prefix b;\n"
" container cont {\n"
" config false;\n"
" leaf l {\n"
@@ -642,8 +642,8 @@
/* state -> config */
str = "module c {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:c;\n"
+ " prefix c;\n"
" container cont {\n"
" leaf l {\n"
" type empty;\n"
@@ -664,8 +664,8 @@
/* notif -> state */
str = "module d {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:d;\n"
+ " prefix d;\n"
" container cont {\n"
" config false;\n"
" leaf l {\n"
@@ -686,8 +686,8 @@
/* notif -> notif */
str = "module e {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:e;\n"
+ " prefix e;\n"
" notification notif {\n"
" leaf l {\n"
" type empty;\n"
@@ -705,8 +705,8 @@
/* rpc input -> state */
str = "module f {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:f;\n"
+ " prefix f;\n"
" container cont {\n"
" config false;\n"
" leaf l {\n"
@@ -729,8 +729,8 @@
/* rpc input -> rpc input */
str = "module g {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:g;\n"
+ " prefix g;\n"
" rpc rp {\n"
" input {\n"
" leaf l {\n"
@@ -750,8 +750,8 @@
/* rpc input -> rpc output leafref */
str = "module h {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:h;\n"
+ " prefix h;\n"
" rpc rp {\n"
" input {\n"
" leaf l2 {\n"
@@ -772,8 +772,8 @@
/* rpc input -> rpc output must */
str = "module h {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:h;\n"
+ " prefix h;\n"
" rpc rp {\n"
" input {\n"
" leaf l2 {\n"
@@ -793,8 +793,8 @@
/* rpc input -> notif leafref */
str = "module i {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:i;\n"
+ " prefix i;\n"
" rpc rp {\n"
" input {\n"
" leaf l2 {\n"
@@ -815,8 +815,8 @@
/* rpc input -> notif must */
str = "module i {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:i;\n"
+ " prefix i;\n"
" rpc rp {\n"
" input {\n"
" leaf l2 {\n"
@@ -838,8 +838,8 @@
/* action output -> state */
str = "module j {\n"
" yang-version 1.1;\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:j;\n"
+ " prefix j;\n"
" container cont {\n"
" list ll {\n"
" key k;\n"
@@ -869,8 +869,8 @@
/* action output -> action input leafref */
str = "module k {\n"
" yang-version 1.1;\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:k;\n"
+ " prefix k;\n"
" container cont {\n"
" list ll {\n"
" key k;\n"
@@ -900,8 +900,8 @@
/* action output -> action input must */
str = "module k {\n"
" yang-version 1.1;\n"
- " namespace urn:a;\n"
- " prefix a;\n"
+ " namespace urn:k;\n"
+ " prefix k;\n"
" container cont {\n"
" list ll {\n"
" key k;\n"
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index f57f4ab..37f23fc 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -1287,10 +1287,10 @@
"typedef mytype2 {type mytype {fraction-digits 3;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid fraction-digits substatement for type \"mytype2\" not directly derived from decimal64 built-in type.", "/de:l");
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;typedef mytype {type decimal64 {"
"fraction-digits 18;range '-10 .. 0';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid range restriction - invalid value \"-10000000000000000000\".", "/ee:l");
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;typedef mytype {type decimal64 {"
"fraction-digits 18;range '0 .. 10';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid range restriction - invalid value \"10000000000000000000\".", "/ee:l");
}
@@ -2428,7 +2428,7 @@
assert_null(leaf->when[0]->context);
UTEST_LOG_CLEAN;
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:ii;prefix ii;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;"
"grouping grp {leaf l {type string;}leaf k {type string; status obsolete;}}"
"uses grp {status deprecated;}}", LYS_IN_YANG, &mod));
assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype);
@@ -2897,7 +2897,7 @@
"augment /func {leaf x {type int8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Augment target node \"/func\" from module \"gg\" was not found.", "/gg:{augment='/func'}");
- assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:i;prefix i;import himp {prefix hi;}"
+ assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;import himp {prefix hi;}"
"augment /hi:func/input {leaf x {type string;}}"
"augment /hi:func/output {leaf y {type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Augment target node \"/hi:func/input\" from module \"hh\" was not found.", "/hh:{augment='/hi:func/input'}");