xpath BUGFIX do not parse empty NCNames
diff --git a/src/xpath.c b/src/xpath.c
index 4232b72..9f4d173 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -2942,7 +2942,7 @@
/* NameTest (NCName ':' '*' | QName) or NodeType/FunctionName */
long int ncname_len = parse_ncname(&expr_str[parsed]);
- LY_CHECK_ERR_GOTO(ncname_len < 0, LOGVAL(ctx, LY_VCODE_XP_INEXPR, expr_str[parsed - ncname_len],
+ LY_CHECK_ERR_GOTO(ncname_len < 1, LOGVAL(ctx, LY_VCODE_XP_INEXPR, expr_str[parsed - ncname_len],
parsed - ncname_len + 1, expr_str); ret = LY_EVALID, error);
tok_len = ncname_len;
@@ -2952,7 +2952,7 @@
++tok_len;
} else {
ncname_len = parse_ncname(&expr_str[parsed + tok_len]);
- LY_CHECK_ERR_GOTO(ncname_len < 0, LOGVAL(ctx, LY_VCODE_XP_INEXPR, expr_str[parsed - ncname_len],
+ LY_CHECK_ERR_GOTO(ncname_len < 1, LOGVAL(ctx, LY_VCODE_XP_INEXPR, expr_str[parsed - ncname_len],
parsed - ncname_len + 1, expr_str); ret = LY_EVALID, error);
tok_len += ncname_len;
}
diff --git a/tests/utests/basic/test_xpath.c b/tests/utests/basic/test_xpath.c
index 889874b..9a6c37c 100644
--- a/tests/utests/basic/test_xpath.c
+++ b/tests/utests/basic/test_xpath.c
@@ -96,6 +96,26 @@
}
static void
+test_invalid(void **state)
+{
+ const char *data =
+ "<foo2 xmlns=\"urn:tests:a\">50</foo2>";
+ struct lyd_node *tree;
+ struct ly_set *set;
+
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
+ assert_non_null(tree);
+
+ assert_int_equal(LY_EVALID, lyd_find_xpath(tree, "/a:foo2[.=]", &set));
+ assert_null(set);
+
+ assert_int_equal(LY_EVALID, lyd_find_xpath(tree, "/a:", &set));
+ assert_null(set);
+
+ lyd_free_all(tree);
+}
+
+static void
test_hash(void **state)
{
const char *data =
@@ -375,6 +395,7 @@
main(void)
{
const struct CMUnitTest tests[] = {
+ UTEST(test_invalid, setup),
UTEST(test_hash, setup),
UTEST(test_toplevel, setup),
UTEST(test_atomize, setup),
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 8c96af9..4e45a59 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -1827,7 +1827,7 @@
"leaf address {type leafref{ path \"/interface[name = current()/../$node]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"xx\" failed.", NULL,
- "Invalid character 0x24 ('$'), perhaps \"\" is supposed to be a function call.", "Line number 4.");
+ "Invalid character '$'[32] of expression '/interface[name = current()/../$node]/ip'.", "Line number 4.");
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module yy {namespace urn:yy;prefix yy;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
diff --git a/tests/utests/types/yang_types.c b/tests/utests/types/yang_types.c
index c157f26..1e89375 100644
--- a/tests/utests/types/yang_types.c
+++ b/tests/utests/types/yang_types.c
@@ -106,7 +106,7 @@
TEST_ERROR_XML("a\" xmlns:yl=\"urn:ietf:params:xml:ns:yang:ietf-yang-library", "l2",
"/yl:yang-library/yl:datastore/yl::name");
CHECK_LOG_CTX("Storing value \"/yl:yang-library/yl:datastore/yl::name\" failed.", "Schema location /a:l2, line number 1.",
- "Invalid character ':'[34] of expression '/yl:yang-library/yl:datastore/yl::name'.",
+ "Invalid character 'y'[31] of expression '/yl:yang-library/yl:datastore/yl::name'.",
"Schema location /a:l2, line number 1.");
}