diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a26bd80..c65ce124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ Developers may need to change their code ### Corrected Bugs +* Fixed: [xpath // abbreviation does not work other than on the top-level](https://github.com/clicon/clixon/issues/435) * Fixed: [if-feature always negative if imported from another module](https://github.com/clicon/clixon/issues/429) * Fixed autocli edit modes for schema mounts diff --git a/lib/src/clixon_xpath_eval.c b/lib/src/clixon_xpath_eval.c index de56cc71..48bbb1b0 100644 --- a/lib/src/clixon_xpath_eval.c +++ b/lib/src/clixon_xpath_eval.c @@ -1287,8 +1287,12 @@ xp_eval(xp_ctx *xc, break; case XP_RELLOCPATH: use_xr0++; - if (xs->xs_int == A_DESCENDANT_OR_SELF) - xc->xc_descendant = 1; /* XXX need to set to 0 in sub */ + if (xs->xs_int == A_DESCENDANT_OR_SELF){ + if (use_xr0) + xr0->xc_descendant = 1; /* XXX need to set to 0 in sub */ + else + xc->xc_descendant = 1; /* XXX need to set to 0 in sub */ + } break; case XP_NODE: break; @@ -1347,7 +1351,10 @@ xp_eval(xp_ctx *xc, break; } } - xc->xc_descendant = 0; + if (use_xr0) + xr0->xc_descendant = 0; + else + xc->xc_descendant = 0; if (xr0 == NULL && xr1 == NULL && xr2 == NULL){ clicon_err(OE_XML, EFAULT, "Internal error: no result produced"); goto done; diff --git a/test/test_xpath.sh b/test/test_xpath.sh index 1f5c7d18..e58ca4ab 100755 --- a/test/test_xpath.sh +++ b/test/test_xpath.sh @@ -176,8 +176,19 @@ new "xpath /aaa/bbb union " expectpart "$($clixon_util_xpath -D $DBG -f $xml -p "aaa/bbb[ccc=42]|aaa/ddd[ccc=22]")" 0 '^nodeset:0:421:22$' new "xpath //bbb" -expectpart "$($clixon_util_xpath -D $DBG -f $xml -p //bbb)" 0 "0:42 -1:99" +expectpart "$($clixon_util_xpath -D $DBG -f $xml -p //bbb)" 0 "0:42" "1:99" + +new "xpath //ccc" +expectpart "$($clixon_util_xpath -D $DBG -f $xml -p //ccc)" 0 "0:42" "1:99" "2:22" + +new "xpath /descendant-or-self::node()/ccc" +expectpart "$($clixon_util_xpath -D $DBG -f $xml -p /descendant-or-self::node\(\)/ccc)" 0 "0:42" "1:99" "2:22" + +new "xpath /aaa//ccc" +expectpart "$($clixon_util_xpath -D $DBG -f $xml -p /aaa//ccc)" 0 "0:42" "1:99" "2:22" + +new "xpath /aaa/descendant-or-self::node()/ccc" +expectpart "$($clixon_util_xpath -D $DBG -f $xml -p /aaa/descendant-or-self::node\(\)/ccc)" 0 "0:42" "1:99" "2:22" new "xpath //b?b" #expecteof "$clixon_util_xpath -D $DBG -f $xml" 0 "//b?b" ""