After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 775683 - xpath context node is lost after nodeset merge
xpath context node is lost after nodeset merge
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: xpath
git master
Other Linux
: Normal normal
: ---
Assigned To: Nick Wellnhofer
libxml QA maintainers
: 648327 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2016-12-06 06:08 UTC by Oleg Paraschenko
Modified: 2018-11-30 20:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Minimal example (441 bytes, application/x-python)
2016-12-06 06:08 UTC, Oleg Paraschenko
Details

Description Oleg Paraschenko 2016-12-06 06:08:39 UTC
Created attachment 341447 [details]
Minimal example

libxml2 loses the context node after joining nodesets from local and global "//".

The sample program below prints two "bar" nodes for each "doc", but it should print only one. And it prints one "bar" node if I restore the context node (uncomment the line (2)) or simplify the expression on the line (1).

import libxml2

s = """
<x>
  <doc> <foo /> <bar /> </doc>
  <doc> <foo /> <bar /> </doc>
</x>"""
xmldoc = libxml2.parseDoc(s)
baton = xmldoc.xpathNewContext()

res = baton.xpathEval("//doc")
for doc_node in res:
    baton.setContextNode(doc_node)
    res = baton.xpathEval(".//foo | //foo") # (1)
    #baton.setContextNode(doc_node) # (2)
    res2 = baton.xpathEval(".//bar") # (3)
    print res2

baton.xpathFreeContext()
xmldoc.freeDoc()
Comment 1 Daniel Veillard 2016-12-06 17:16:42 UTC
 yes if you manipulate at that level, the input to
a query on the evaluation context is both the XPath expression
and the context node (c.f. XPath spec introduction)

 To be honnest I would be worried of changing the default behaviour
at this point. There is always a risk of introducing a regression
in software relying on some side effect.

Daniel
Comment 2 Oleg Paraschenko 2016-12-13 10:32:49 UTC
For me, it looks very much like a bug, and I can't imagine how software can rely on re-setting the context node behind the scene.

Anyway, I can believe that there are reasons not to correct the issue, but while such behavior is very unexpected, I'd recommend at least to document it.
Comment 3 Nick Wellnhofer 2017-06-08 12:21:16 UTC
*** Bug 648327 has been marked as a duplicate of this bug. ***