xpath BUGFIX current() result for root ctx node
diff --git a/src/xpath.c b/src/xpath.c
index 15404c7..ed24eb1 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -3700,12 +3700,22 @@
if (options & LYXP_SCNODE_ALL) {
set_scnode_clear_ctx(set, LYXP_SET_SCNODE_ATOM_NODE);
- LY_CHECK_RET(lyxp_set_scnode_insert_node(set, set->cur_scnode, LYXP_NODE_ELEM, NULL));
+ if (set->cur_scnode) {
+ LY_CHECK_RET(lyxp_set_scnode_insert_node(set, set->cur_scnode, LYXP_NODE_ELEM, NULL));
+ } else {
+ /* root node */
+ LY_CHECK_RET(lyxp_set_scnode_insert_node(set, NULL, set->root_type, NULL));
+ }
} else {
lyxp_set_free_content(set);
- /* position is filled later */
- set_insert_node(set, set->cur_node, 0, LYXP_NODE_ELEM, 0);
+ if (set->cur_node) {
+ /* position is filled later */
+ set_insert_node(set, set->cur_node, 0, LYXP_NODE_ELEM, 0);
+ } else {
+ /* root node */
+ set_insert_node(set, NULL, 0, set->root_type, 0);
+ }
}
return LY_SUCCESS;