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 703580 - XPath evaluator sometimes binds // stronger than []
XPath evaluator sometimes binds // stronger than []
Status: RESOLVED DUPLICATE of bug 695699
Product: libxml2
Classification: Platform
Component: general
git master
Other Linux
: Normal major
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2013-07-03 23:55 UTC by John Chadwick
Modified: 2013-07-04 00:15 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description John Chadwick 2013-07-03 23:55:28 UTC
Since revision 62270539, entitled 'Optimizing '//' in XPath expressions,' the XPath evaluator has been incorrectly handling some XPath expressions such that // binds stronger than []. Consider the following expression:

    //a[1]

In expanded syntax, this is:

    /descendant-or-self::node()/a[1]

After revision 62270539, it becomes:

    /descendant::a[1]

Which is (incorrectly) equivalent to:

    (/descendant-or-self::node()/a)[1]

Which will return the first a node in the document, whereas //a[1] will return every a node that is the first child of their respective container.

The XPath 1.0 specification actually covers this:

    NOTE: The location path //para[1] does not mean the same as the location
    path /descendant::para[1]. The latter selects the first descendant para 
    element; the former selects all descendant para elements that are the first 
    para children of their parents.

I have not thought out a fool-proof solution, but I'm guessing the correct way to handle this is to disable the optimization if there are predicates attached to the location step.
Comment 1 John Chadwick 2013-07-04 00:15:36 UTC
Whoops... I blew it. Turns out this was already described in bug 695699, but I missed it because at first it was talking about another issue.

*** This bug has been marked as a duplicate of bug 695699 ***