diff --git a/CHANGELOG.md b/CHANGELOG.md index 95f7d3e8..593e8f14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ Users may have to change how they access the system ### Corrected Bugs +* Fix Union in xpath [XPATH issues #219](https://github.com/clicon/clixon/issues/219) * Fix: XPath:s used in netconf (eg get-config) did not correctly access default values * [RESTCONF GET request of single-key list with empty string returns all elements #213](https://github.com/clicon/clixon/issues/213) * [RESTCONF GETof lists with empty string keys does not work #214](https://github.com/clicon/clixon/issues/214) diff --git a/apps/cli/cli_generate.c b/apps/cli/cli_generate.c index 6e7b8f5e..7712ccfb 100644 --- a/apps/cli/cli_generate.c +++ b/apps/cli/cli_generate.c @@ -121,13 +121,12 @@ cli_expand_var_generate(clicon_handle h, int retval = -1; char *api_path_fmt = NULL, *opext = NULL; - if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0) + if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0) goto done; - if (opext && strcmp(opext, "hide-database") == 0) { - retval = 1; - goto done; - } - + if (opext && strcmp(opext, "hide-database") == 0) { + retval = 1; + goto done; + } if (yang2api_path_fmt(ys, 1, &api_path_fmt) < 0) goto done; cprintf(cb, "|<%s:%s", yang_argument_get(ys), diff --git a/example/main/example_cli.cli b/example/main/example_cli.cli index 1b28899a..8f05995d 100644 --- a/example/main/example_cli.cli +++ b/example/main/example_cli.cli @@ -69,6 +69,7 @@ discard("Discard edits (rollback 0)"), discard_changes(); compare("Compare running and candidate"), compare_dbs((int32)1); show("Show a particular state of the system"){ + auto("Show expand") @datamodel, cli_show_auto("candidate", "xml"); xpath("Show configuration") ("XPATH expression") ("Namespace"), show_conf_xpath("candidate"); version("Show version"), cli_show_version("candidate", "text", "/"); options("Show clixon options"), cli_show_options(); diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index 22733cfa..dd632471 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -488,10 +488,10 @@ text_modify(clicon_handle h, /* If origin body has namespace definitions, copy them. The reason is that * some bodies rely on namespace prefixes, such as NACM path, but there is - * no way we can now this here. + * no way we can know this here. * However, this may lead to namespace collisions if these prefixes are not * canonical, and may collide with the assign_namespace_element() above (but that - * is for element sysmbols) + * is for element symbols) * Oh well. */ if (assign_namespace_body(x1, x1bstr, x0) < 0) diff --git a/lib/src/clixon_xpath.c b/lib/src/clixon_xpath.c index a1843e57..5be20e27 100644 --- a/lib/src/clixon_xpath.c +++ b/lib/src/clixon_xpath.c @@ -34,6 +34,14 @@ * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 * + * Note on xcur parameter to most xpath functions: + * The W3 standard defines the document root / element as the top-level. + * In the clixon xpath API, the document root is defined as the top of the xml tree. + * The xcur argument of xpath_first and others is the "current" xml node (xcur) which can + * be any node in that tree, not necessarily the document root. + * This is convenient if you want to use relative xpaths from any location in the tree (eg ../../foo/bar). + * It may be confusing if you expect xcur to be the root node. + * * Some notes on namespace extensions in Netconf/Yang * 1) The xpath is not "namespace-aware" in the sense that if you look for a path, eg * "n:a/n:b", those must match the XML, so they need to match prefixes AND name in the xml diff --git a/lib/src/clixon_xpath_parse.y b/lib/src/clixon_xpath_parse.y index e016a4a0..91c383e5 100644 --- a/lib/src/clixon_xpath_parse.y +++ b/lib/src/clixon_xpath_parse.y @@ -387,7 +387,7 @@ addexpr : addexpr ADDOP unionexpr { $$=xp_new(XP_ADD,$2,NULL,NULL,NULL,$1, $ ; /* node-set */ -unionexpr : unionexpr '|' pathexpr { $$=xp_new(XP_UNION,A_NAN,NULL,NULL,NULL,$1, $3);clicon_debug(3,"unionexpr-> unionexpr | pathexpr"); } +unionexpr : unionexpr '|' pathexpr { $$=xp_new(XP_UNION,XO_UNION,NULL,NULL,NULL,$1, $3);clicon_debug(3,"unionexpr-> unionexpr | pathexpr"); } | pathexpr { $$=xp_new(XP_UNION,A_NAN,NULL,NULL,NULL,$1, NULL);clicon_debug(3,"unionexpr-> pathexpr"); } ; diff --git a/test/test_openconfig_interfaces.sh b/test/test_openconfig_interfaces.sh index b7fde3e4..7f24fffc 100755 --- a/test/test_openconfig_interfaces.sh +++ b/test/test_openconfig_interfaces.sh @@ -111,6 +111,10 @@ expectpart "$($clixon_cli -1 -f $cfg show conf xml)" 0 "^ complete: e" expectpart "$(echo "set interfaces interface " | $clixon_cli -f $cfg)" 0 "interface e" +# XXX See https://github.com/clicon/clixon/issues/218 +#new "cli set interfaces interface e complete: not ethernet" +#expectpart "$(echo "set interfaces interface e " | $clixon_cli -f $cfg)" 0 config hold-time subinterfaces --not-- ethernet + if [ $BE -ne 0 ]; then new "Kill backend" # Check if premature kill diff --git a/test/test_xpath.sh b/test/test_xpath.sh index 697895d6..47be4e2e 100755 --- a/test/test_xpath.sh +++ b/test/test_xpath.sh @@ -88,6 +88,9 @@ new "xpath /aaa/bbb" expecteof "$clixon_util_xpath -f $xml -p /aaa/bbb" 0 "" "^0:42 1:99$" +new "xpath /aaa/bbb union " +expecteof "$clixon_util_xpath -f $xml -p aaa/bbb[ccc=42]|aaa/ddd[ccc=22]" 0 "" '^nodeset:0:421:22$' + new "xpath //bbb" expecteof "$clixon_util_xpath -f $xml -p //bbb" 0 "" "0:42 1:99"