From be2cf64ca7956f2c57e596dc80ecdd6e97fc828c Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Wed, 18 Nov 2026 11:56:35 +0100 Subject: [PATCH 1/3] tree schema BUGFIX always resolve prefix if set --- src/tree_schema.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tree_schema.c b/src/tree_schema.c index 5a97b4cc6..b6f566b7c 100644 --- a/src/tree_schema.c +++ b/src/tree_schema.c @@ -565,7 +565,7 @@ lys_find_child_node(const struct ly_ctx *ctx, const struct lysc_node *parent, co } /* find the module */ - if (!mod) { + if (prefix || !mod) { mod = lys_find_module(ctx, parent, prefix, prefix_len, format, prefix_data); } From 4454131fcc684f2b0594dde88e17dfc12a210832 Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Wed, 18 Nov 2026 11:57:06 +0100 Subject: [PATCH 2/3] xpath1.0 BUGFIX support for mounted nodes Fixes #2621 --- src/plugins_types.h | 11 +-- src/plugins_types/instanceid_keys.c | 7 +- src/plugins_types/xpath1.0.c | 118 +++++++++++++++++++--------- tests/utests/basic/test_common.c | 33 +++----- 4 files changed, 100 insertions(+), 69 deletions(-) diff --git a/src/plugins_types.h b/src/plugins_types.h index feabb5c93..4118d4532 100644 --- a/src/plugins_types.h +++ b/src/plugins_types.h @@ -142,7 +142,7 @@ struct lysc_type_leafref; /** * @brief Type API version */ -#define LYPLG_TYPE_API_VERSION 4 +#define LYPLG_TYPE_API_VERSION 5 /** * @brief Type of the LYB size of a value of a particular type. @@ -343,20 +343,21 @@ LIBYANG_API_DECL ly_bool lyplg_type_bits_is_bit_set(const char *bitmap, uint32_t * @param[in] token Token to transform. * @param[in] tok_len Lenghth of @p token. * @param[in] is_nametest Whether the token is a nametest, it then always requires a prefix in XML @p get_format. - * @param[in,out] context_mod Current context module, may be updated. * @param[in] resolve_ctx Context to use for resolving prefixes. * @param[in] resolve_format Format of the resolved prefixes. * @param[in] resolve_prefix_data Resolved prefixes prefix data. * @param[in] get_format Format of the output prefixes. * @param[in] get_prefix_data Format-specific prefix data for the output. + * @param[in,out] ctx_mod Current context module, may be updated. + * @param[in,out] ctx_node Current context node, may be updated. * @param[out] token_p Printed token. * @param[out] err Error structure on error. * @return LY_ERR value. */ LIBYANG_API_DECL LY_ERR lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_nametest, - const struct lys_module **context_mod, const struct ly_ctx *resolve_ctx, LY_VALUE_FORMAT resolve_format, - const void *resolve_prefix_data, LY_VALUE_FORMAT get_format, void *get_prefix_data, char **token_p, - struct ly_err_item **err); + const struct ly_ctx *resolve_ctx, LY_VALUE_FORMAT resolve_format, const void *resolve_prefix_data, + LY_VALUE_FORMAT get_format, void *get_prefix_data, const struct lys_module **ctx_mod, + const struct lysc_node **ctx_node, char **token_p, struct ly_err_item **err); /** * @brief Get format-specific prefix for a module. diff --git a/src/plugins_types/instanceid_keys.c b/src/plugins_types/instanceid_keys.c index 0b797d3e4..153e3f359 100644 --- a/src/plugins_types/instanceid_keys.c +++ b/src/plugins_types/instanceid_keys.c @@ -65,7 +65,8 @@ instanceid_keys_print_value(const struct lyd_value_instance_identifier_keys *val char *str_tok; const char *cur_exp_ptr; ly_bool is_nt; - const struct lys_module *context_mod = NULL, *local_mod = NULL; + const struct lys_module *local_mod = NULL, *ctx_mod = NULL; + const struct lysc_node *ctx_node = NULL; struct ly_set *mods; *str_value = NULL; @@ -84,8 +85,8 @@ instanceid_keys_print_value(const struct lyd_value_instance_identifier_keys *val if ((cur_tok == LYXP_TOKEN_NAMETEST) || (cur_tok == LYXP_TOKEN_LITERAL)) { /* tokens that may include prefixes, get them in the target format */ is_nt = (cur_tok == LYXP_TOKEN_NAMETEST) ? 1 : 0; - LY_CHECK_GOTO(ret = lyplg_type_xpath10_print_token(cur_exp_ptr, val->keys->tok_len[cur_idx], is_nt, &context_mod, - val->ctx, val->format, val->prefix_data, format, prefix_data, &str_tok, err), cleanup); + LY_CHECK_GOTO(ret = lyplg_type_xpath10_print_token(cur_exp_ptr, val->keys->tok_len[cur_idx], is_nt, val->ctx, + val->format, val->prefix_data, format, prefix_data, &ctx_mod, &ctx_node, &str_tok, err), cleanup); /* append the converted token */ ret = ly_append_str(str_value, &str_size, &str_len, "%s", str_tok); diff --git a/src/plugins_types/xpath1.0.c b/src/plugins_types/xpath1.0.c index 631002f1e..de9338c96 100644 --- a/src/plugins_types/xpath1.0.c +++ b/src/plugins_types/xpath1.0.c @@ -24,6 +24,7 @@ #include "compat.h" #include "dict.h" #include "ly_common.h" +#include "tree_schema_internal.h" #include "xml.h" #include "xpath.h" @@ -37,50 +38,84 @@ */ LIBYANG_API_DEF LY_ERR -lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_nametest, const struct lys_module **context_mod, - const struct ly_ctx *resolve_ctx, LY_VALUE_FORMAT resolve_format, const void *resolve_prefix_data, - LY_VALUE_FORMAT get_format, void *get_prefix_data, char **token_p, struct ly_err_item **err) +lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_nametest, const struct ly_ctx *resolve_ctx, + LY_VALUE_FORMAT resolve_format, const void *resolve_prefix_data, LY_VALUE_FORMAT get_format, void *get_prefix_data, + const struct lys_module **ctx_mod, const struct lysc_node **ctx_node, char **token_p, struct ly_err_item **err) { - LY_ERR ret = LY_SUCCESS; - const char *str_begin, *str_next, *prefix; - ly_bool is_prefix, has_prefix = 0; + LY_ERR rc = LY_SUCCESS, r; + const char *str_begin, *str_next, *str_next2, *prefix; + ly_bool is_prefix, is_prefix2, has_prefix = 0; char *str = NULL; - uint32_t len, str_size = 0, str_len = 0, pref_len; + uint32_t len, len2, str_size = 0, str_len = 0, pref_len; + const struct lysc_node *node = NULL; const struct lys_module *mod; *token_p = NULL; + if (*ctx_mod) { + /* use context module context in case it is from an extension */ + resolve_ctx = (*ctx_mod)->ctx; + } str_begin = token; - while (!(ret = ly_value_prefix_next(str_begin, token + tok_len, &len, &is_prefix, &str_next)) && len) { + while (!(r = ly_value_prefix_next(str_begin, token + tok_len, &len, &is_prefix, &str_next)) && len) { if (!is_prefix) { - if (!has_prefix && is_nametest && (get_format == LY_VALUE_XML) && *context_mod) { + if (!has_prefix && is_nametest && (get_format == LY_VALUE_XML) && *ctx_mod) { /* get the prefix */ - prefix = lyplg_type_get_prefix(*context_mod, get_format, get_prefix_data); + prefix = lyplg_type_get_prefix(*ctx_mod, get_format, get_prefix_data); assert(prefix); /* append the nametest and prefix */ LY_CHECK_ERR_GOTO(ly_append_str(&str, &str_size, &str_len, "%s:%.*s", prefix, (int)len, str_begin), - ret = ly_err_new_no_mem(err), cleanup); + rc = ly_err_new_no_mem(err), cleanup); } else { /* just append the string, we may get the first expression node without a prefix but since this * is not strictly forbidden, allow it */ LY_CHECK_ERR_GOTO(ly_append_str(&str, &str_size, &str_len, "%.*s", (int)len, str_begin), - ret = ly_err_new_no_mem(err), cleanup); + rc = ly_err_new_no_mem(err), cleanup); } } else { /* remember there was a prefix found */ has_prefix = 1; - /* resolve the module in the original format */ - mod = lys_find_module(resolve_ctx, NULL, str_begin, len, resolve_format, resolve_prefix_data); - if (!mod && is_nametest) { - ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to resolve prefix \"%.*s\".", - (int)len, str_begin); - goto cleanup; + if (is_nametest) { + /* parse the name as well */ + r = ly_value_prefix_next(str_next, token + tok_len, &len2, &is_prefix2, &str_next2); + if (r) { + /* invalid characters in the xpath */ + break; + } else if (!len2) { + rc = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Unexpected token end (\"%.*s\").", + (int)((token + tok_len) - str_begin), str_begin); + goto cleanup; + } else if (is_prefix2) { + rc = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Unexpected prefix found (\"%.*s\").", + (int)((token + tok_len) - str_next), str_next); + goto cleanup; + } + + /* find the node */ + r = lys_find_child_node(resolve_ctx, *ctx_node, *ctx_mod, str_begin, len, resolve_format, + (void *)resolve_prefix_data, str_next, len2, 0, &node, NULL); + if (r) { + /* we were not able to find the node but this function does not strictly require it, only the + * module must be found */ + mod = lys_find_module(resolve_ctx, NULL, str_begin, len, resolve_format, resolve_prefix_data); + if (!mod) { + rc = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to resolve prefix \"%.*s\".", + (int)len, str_begin); + goto cleanup; + } + } else { + /* set the current module */ + mod = node->module; + } + } else { + /* resolve the module in the original format */ + mod = lys_find_module(resolve_ctx, NULL, str_begin, len, resolve_format, resolve_prefix_data); } - if (is_nametest && ((get_format == LY_VALUE_JSON) || (get_format == LY_VALUE_LYB)) && (*context_mod == mod)) { + if (is_nametest && ((get_format == LY_VALUE_JSON) || (get_format == LY_VALUE_LYB)) && (*ctx_mod == mod)) { /* inherit the prefix and do not print it again */ } else { if (mod) { @@ -96,30 +131,31 @@ lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_n /* append the prefix */ LY_CHECK_ERR_GOTO(ly_append_str(&str, &str_size, &str_len, "%.*s:", (int)pref_len, prefix), - ret = ly_err_new_no_mem(err), cleanup); + rc = ly_err_new_no_mem(err), cleanup); } if (is_nametest) { - /* update context module */ - *context_mod = mod; + /* update context module and node */ + *ctx_mod = mod; + *ctx_node = node; } } str_begin = str_next; } - if (ret) { + if (r) { /* invalid characters in the xpath */ - ly_err_new(err, ret, LYVE_DATA, NULL, NULL, "Invalid characters found (\"%.*s\").", + rc = ly_err_new(err, r, LYVE_DATA, NULL, NULL, "Invalid characters found (\"%.*s\").", (int)((token + tok_len) - str_begin), str_begin); } cleanup: - if (ret) { + if (rc) { free(str); } else { *token_p = str; } - return ret; + return rc; } /** @@ -127,8 +163,9 @@ lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_n * * @param[in,out] cur_idx Current index of the next token in the expression. * @param[in] end_tok End token (including) that finishes this subexpression parsing. If 0, parse until the end. - * @param[in] context_mod Current context module, some formats (::LY_VALUE_JSON and ::LY_VALUE_LYB) inherit this module - * instead of printing it again. + * @param[in] ctx_mod Current context module, some formats (::LY_VALUE_JSON and ::LY_VALUE_LYB) inherit it instead of + * printing it again. + * @param[in] ctx_node Current context node. * @param[in] xp_val xpath1.0 value structure. * @param[in] format Format to print in. * @param[in] prefix_data Format-specific prefix data. @@ -139,16 +176,17 @@ lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_n * @return LY_ERR value. */ static LY_ERR -xpath10_print_subexpr_r(uint16_t *cur_idx, enum lyxp_token end_tok, const struct lys_module *context_mod, - const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, void *prefix_data, char **str_value, - uint32_t *str_size, uint32_t *str_len, struct ly_err_item **err) +xpath10_print_subexpr_r(uint16_t *cur_idx, enum lyxp_token end_tok, const struct lys_module *ctx_mod, + const struct lysc_node *ctx_node, const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, + void *prefix_data, char **str_value, uint32_t *str_size, uint32_t *str_len, struct ly_err_item **err) { LY_ERR r; enum lyxp_token cur_tok, sub_end_tok; char *str_tok; const char *cur_exp_ptr; ly_bool is_nt; - const struct lys_module *orig_context_mod = context_mod; + const struct lys_module *orig_ctx_mod = ctx_mod; + const struct lysc_node *orig_ctx_node = ctx_node; while (*cur_idx < xp_val->exp->used) { cur_tok = xp_val->exp->tokens[*cur_idx]; @@ -157,8 +195,8 @@ xpath10_print_subexpr_r(uint16_t *cur_idx, enum lyxp_token end_tok, const struct if ((cur_tok == LYXP_TOKEN_NAMETEST) || (cur_tok == LYXP_TOKEN_LITERAL)) { /* tokens that may include prefixes, get them in the target format */ is_nt = (cur_tok == LYXP_TOKEN_NAMETEST) ? 1 : 0; - LY_CHECK_RET(lyplg_type_xpath10_print_token(cur_exp_ptr, xp_val->exp->tok_len[*cur_idx], is_nt, &context_mod, - xp_val->ctx, xp_val->format, xp_val->prefix_data, format, prefix_data, &str_tok, err)); + LY_CHECK_RET(lyplg_type_xpath10_print_token(cur_exp_ptr, xp_val->exp->tok_len[*cur_idx], is_nt, xp_val->ctx, + xp_val->format, xp_val->prefix_data, format, prefix_data, &ctx_mod, &ctx_node, &str_tok, err)); /* append the converted token */ r = ly_append_str(str_value, str_size, str_len, "%s", str_tok); @@ -173,8 +211,9 @@ xpath10_print_subexpr_r(uint16_t *cur_idx, enum lyxp_token end_tok, const struct LY_CHECK_GOTO(ly_append_str(str_value, str_size, str_len, " %.*s ", (int)xp_val->exp->tok_len[*cur_idx], cur_exp_ptr), error_mem); - /* reset context mod */ - context_mod = orig_context_mod; + /* reset context module and node */ + ctx_mod = orig_ctx_mod; + ctx_node = orig_ctx_node; } else { /* just copy the token */ LY_CHECK_GOTO(ly_append_str(str_value, str_size, str_len, "%.*s", (int)xp_val->exp->tok_len[*cur_idx], @@ -191,8 +230,8 @@ xpath10_print_subexpr_r(uint16_t *cur_idx, enum lyxp_token end_tok, const struct sub_end_tok = (cur_tok == LYXP_TOKEN_BRACK1) ? LYXP_TOKEN_BRACK2 : LYXP_TOKEN_PAR2; /* parse the subexpression separately, use the current context mod */ - LY_CHECK_RET(xpath10_print_subexpr_r(cur_idx, sub_end_tok, context_mod, xp_val, format, prefix_data, - str_value, str_size, str_len, err)); + LY_CHECK_RET(xpath10_print_subexpr_r(cur_idx, sub_end_tok, ctx_mod, ctx_node, xp_val, format, + prefix_data, str_value, str_size, str_len, err)); } } } @@ -238,7 +277,8 @@ lyplg_type_print_xpath10_value(const struct lyd_value_xpath10 *xp_val, LY_VALUE_ } /* recursively print the expression */ - ret = xpath10_print_subexpr_r(&expr_idx, 0, NULL, xp_val, format, prefix_data, str_value, &str_size, &str_len, err); + ret = xpath10_print_subexpr_r(&expr_idx, 0, NULL, NULL, xp_val, format, prefix_data, str_value, &str_size, &str_len, + err); if (local_mod) { mods->objs[0] = (void *)local_mod; diff --git a/tests/utests/basic/test_common.c b/tests/utests/basic/test_common.c index ef119ad2d..920e20e3d 100644 --- a/tests/utests/basic/test_common.c +++ b/tests/utests/basic/test_common.c @@ -310,31 +310,21 @@ test_parse_instance_predicate(void **state) * @param token The input token to translate. * @param tok_len The length of the input token. * @param is_nametest Whether the token is a name test. - * @param mod The YANG module. + * @param mod Module to use. * @param expected_ret The expected return value. * @param expected_out The expected output token. */ static void -assert_token_translation(const char *token, uint16_t tok_len, ly_bool is_nametest, - struct lys_module *mod, LY_ERR expected_ret) +assert_token_translation(const char *token, uint16_t tok_len, ly_bool is_nametest, const struct lys_module *mod, + LY_ERR expected_ret) { + LY_ERR r; char *out_token = NULL; - const struct lys_module *context_mod = mod; - - LY_ERR ret = lyplg_type_xpath10_print_token( - token, - tok_len, - is_nametest, - &context_mod, - mod->ctx, - LY_VALUE_SCHEMA, - mod->parsed, - LY_VALUE_JSON, - NULL, - &out_token, - NULL); - - assert_int_equal(expected_ret, ret); + const struct lysc_node *ctx_node = NULL; + + r = lyplg_type_xpath10_print_token(token, tok_len, is_nametest, mod->ctx, LY_VALUE_SCHEMA, mod->parsed, + LY_VALUE_JSON, NULL, &mod, &ctx_node, &out_token, NULL); + assert_int_equal(expected_ret, r); free(out_token); } @@ -347,6 +337,8 @@ test_value_prefix_next(void **state) "module test {" " namespace \"urn:test\";" " prefix pref;" + "" + " leaf node {type string;}" "}"; assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, yang, LYS_IN_YANG, &mod)); @@ -357,9 +349,6 @@ test_value_prefix_next(void **state) /* Valid prefix with node (Prefix translation) */ assert_token_translation("pref:node", 9, 1, mod, LY_SUCCESS); - /* Valid prefix only (Nametest ending in colon) */ - assert_token_translation("pref:", 5, 1, mod, LY_SUCCESS); - /* No prefix (Standard node) */ assert_token_translation("node", 4, 1, mod, LY_SUCCESS); From 94de624195dd1e1d80f7287d3570d63e3163ce91 Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Wed, 18 Nov 2026 11:59:28 +0100 Subject: [PATCH 3/3] actions BUGFIX rocky 9 default shell not found --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 568ced5d4..c34487380 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -344,7 +344,8 @@ jobs: ${{ matrix.config.pkg-setup }} ${{ matrix.config.pkg-cmd }} ${{ matrix.config.pkg-packages }} ${{ matrix.config.pipx-install }} - echo "$HOME/.local/bin" >> $GITHUB_PATH + # messes up PATH on Rocky so sh is not found in the next step ??? + # echo "$HOME/.local/bin" >> "$GITHUB_PATH" pipx install apkg $HOME/.local/bin/apkg system-setup @@ -352,5 +353,5 @@ jobs: run: | git clone -b ${{ needs.git-branch.outputs.branch-name }} https://github.com/CESNET/libyang.git cd libyang - apkg build - apkg install + $HOME/.local/bin/apkg build + $HOME/.local/bin/apkg install