yanglint BUGFIX added xpath check
diff --git a/tools/lint/common.c b/tools/lint/common.c
index 4afba03..298936f 100644
--- a/tools/lint/common.c
+++ b/tools/lint/common.c
@@ -606,6 +606,7 @@
LY_ERR ret = LY_SUCCESS;
struct lyd_node *tree = NULL, *op = NULL, *envp = NULL, *merged_tree = NULL, *oper_tree = NULL;
char *path = NULL;
+ const char *xpath;
struct ly_set *set = NULL;
/* additional operational datastore */
@@ -769,7 +770,15 @@
}
for (uint32_t u = 0; xpaths && (u < xpaths->count); ++u) {
- if (evaluate_xpath(merged_tree, (const char *)xpaths->objs[u])) {
+ xpath = (const char *)xpaths->objs[u];
+ ly_set_free(set, NULL);
+ ret = lys_find_xpath(ctx, NULL, xpath, LYS_FIND_NO_MATCH_ERROR, &set);
+ if (ret || !set->count) {
+ ret = (ret == LY_SUCCESS) ? LY_EINVAL : ret;
+ YLMSG_E("The requested xpath failed.\n");
+ goto cleanup;
+ }
+ if (evaluate_xpath(merged_tree, xpath)) {
goto cleanup;
}
}
diff --git a/tools/lint/tests/interactive/data_xpath.test b/tools/lint/tests/interactive/data_xpath.test
index a1dabbc..25da774 100644
--- a/tools/lint/tests/interactive/data_xpath.test
+++ b/tools/lint/tests/interactive/data_xpath.test
@@ -36,6 +36,12 @@
ly_cmd "data -x /moddatanodes:dnc/con $data" "container \"con\""
}}
+test data_xpath_wrong_path {--xpath to a non-existent node} {
+-setup $ly_setup -cleanup $ly_cleanup -body {
+ ly_cmd "load moddatanodes"
+ ly_cmd_err "data -x /moddatanodes:dnc/wrng $data" "xpath failed"
+}}
+
test data_xpath_err_default {--xpath cannot be combined with --default} {
-setup $ly_setup -cleanup $ly_cleanup -body {
ly_cmd "load moddatanodes ietf-netconf-with-defaults"