Skip to content

Commit bb6c1a5

Browse files
committed
xpath BUGFIX special * path is not limited to context module
1 parent 5ba68e7 commit bb6c1a5

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/xpath.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,12 +5167,11 @@ moveto_node_add(struct lyxp_set *set, struct lyd_node *node, uint32_t pos, uint3
51675167
* @param[in] qname Qualified node name to move to.
51685168
* @param[in] qname_len Length of \p qname.
51695169
* @param[in] options Whether to apply data node access restrictions defined for 'when' and 'must' evaluation.
5170-
* @param[in] all_ns Flag simulating an expression in the form "*:qname", which is not a valid XPath.
51715170
*
51725171
* @return EXIT_SUCCESS on success, EXIT_FAILURE on unresolved when, -1 on error.
51735172
*/
51745173
static int
5175-
moveto_node(struct lyxp_set *set, struct lyd_node *cur_node, const char *qname, uint16_t qname_len, int options, int all_ns)
5174+
moveto_node(struct lyxp_set *set, struct lyd_node *cur_node, const char *qname, uint16_t qname_len, int options)
51765175
{
51775176
uint32_t i;
51785177
int replaced, pref_len, ret;
@@ -5198,6 +5197,7 @@ moveto_node(struct lyxp_set *set, struct lyd_node *cur_node, const char *qname,
51985197

51995198
/* prefix */
52005199
if ((ptr = strnchr(qname, ':', qname_len))) {
5200+
/* specific module */
52015201
pref_len = ptr - qname;
52025202
moveto_mod = moveto_resolve_model(qname, pref_len, ctx, NULL, 1);
52035203
if (!moveto_mod) {
@@ -5206,7 +5206,11 @@ moveto_node(struct lyxp_set *set, struct lyd_node *cur_node, const char *qname,
52065206
}
52075207
qname += pref_len + 1;
52085208
qname_len -= pref_len + 1;
5209+
} else if ((qname[0] == '*') && (qname_len == 1)) {
5210+
/* all modules - special case */
5211+
moveto_mod = NULL;
52095212
} else {
5213+
/* content node module */
52105214
moveto_mod = lyd_node_module(cur_node);
52115215
}
52125216

@@ -5218,7 +5222,7 @@ moveto_node(struct lyxp_set *set, struct lyd_node *cur_node, const char *qname,
52185222

52195223
if ((set->val.nodes[i].type == LYXP_NODE_ROOT_CONFIG) || (set->val.nodes[i].type == LYXP_NODE_ROOT)) {
52205224
LY_TREE_FOR(set->val.nodes[i].node, sub) {
5221-
ret = moveto_node_check(sub, root_type, name_dict, all_ns ? NULL : moveto_mod, options);
5225+
ret = moveto_node_check(sub, root_type, name_dict, moveto_mod, options);
52225226
if (!ret) {
52235227
/* pos filled later */
52245228
moveto_node_add(set, sub, 0, i, &replaced);
@@ -5234,7 +5238,7 @@ moveto_node(struct lyxp_set *set, struct lyd_node *cur_node, const char *qname,
52345238
&& !(set->val.nodes[i].node->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA))) {
52355239

52365240
LY_TREE_FOR(set->val.nodes[i].node->child, sub) {
5237-
ret = moveto_node_check(sub, root_type, name_dict, all_ns ? NULL : moveto_mod, options);
5241+
ret = moveto_node_check(sub, root_type, name_dict, moveto_mod, options);
52385242
if (!ret) {
52395243
moveto_node_add(set, sub, 0, i, &replaced);
52405244
++i;
@@ -5414,8 +5418,8 @@ moveto_node_alldesc(struct lyxp_set *set, struct lyd_node *cur_node, const char
54145418
moveto_mod = NULL;
54155419
}
54165420

5417-
/* special path, replace the original nodes (and throws away all text and attr nodes, root is replaced by a child) */
5418-
ret = moveto_node(set, cur_node, "*", 1, options, 1);
5421+
/* replace the original nodes (and throws away all text and attr nodes, root is replaced by a child) */
5422+
ret = moveto_node(set, cur_node, "*", 1, options);
54195423
if (ret) {
54205424
return ret;
54215425
}
@@ -6528,7 +6532,7 @@ eval_node_test(struct lyxp_expr *exp, uint16_t *exp_idx, struct lyd_node *cur_no
65286532
exp->tok_len[*exp_idx], options);
65296533
} else {
65306534
rc = moveto_node(set, cur_node, &exp->expr[exp->expr_pos[*exp_idx]], exp->tok_len[*exp_idx],
6531-
options, 0);
6535+
options);
65326536
}
65336537
}
65346538

0 commit comments

Comments
 (0)