Bug 1357971 - libxml2 xpath differences between two versions
Summary: libxml2 xpath differences between two versions
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: libxml2
Version: 24
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Daniel Veillard
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-07-19 17:12 UTC by Ali Akcaagac
Modified: 2016-07-27 16:15 UTC (History)
4 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2016-07-27 16:15:19 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
old version (29 bytes, text/html)
2016-07-19 17:12 UTC, Ali Akcaagac
no flags Details
new version (3.38 KB, text/html)
2016-07-19 17:13 UTC, Ali Akcaagac
no flags Details

Description Ali Akcaagac 2016-07-19 17:12:57 UTC
Created attachment 1181748 [details]
old version

I recently took out one of my older scripts that xpaths a few XML lines online.

The command is rather simple:

xmllint --xpath "//title[1]" "http://derStandard.at/?page=rss"

Unfortunately I realized that the output from

libxml2-2.9.1-5.fc22.i686.rpm

towards

libxml2-2.9.2-1.fc22.i686.rpm

and upwards has changed.

The xpath should return the first element of title in an array of titles. While 2.9.1-5 (and older version that also came bundled with e.g. fedora 20) works as I expect, the version that came after that returns *all* title elements.

Please find attached 2 log files showing the returned content.

Might this be an uncovered issue ?

Btw: I am reporting this bug for fedora 22 and would like to receive a fixed package for it. If possible.

Comment 1 Ali Akcaagac 2016-07-19 17:13:32 UTC
Created attachment 1181749 [details]
new version

All versions after that seem to be affected by this issue.

Comment 2 Ali Akcaagac 2016-07-19 17:51:03 UTC
Ok saw that Fedora 22 received EOL today *darn* but the bug might be still valid one. Please test and fix. Will be updating to Fedora 24 in a couple of days anyways.

Comment 3 Ali Akcaagac 2016-07-27 13:19:44 UTC
I just tested this under Fedora 24 and the problem is there too. I had to recompile an old Fedora 22 Version for Fedora 24 to get the XPath correctly. It would be nice to have that one solved. Thanks.

Comment 4 Ali Akcaagac 2016-07-27 15:32:31 UTC
I was able to track the issue down to this:

-----------------------------------------
commit b4bcba23f64b71105514875f165a63d4cc720609
Author: Nick Wellnhofer <wellnhofer>
Date:   Mon Aug 5 00:15:11 2013 +0200

    Fix XPath '//' optimization with predicates
    
    My attempt to optimize XPath expressions containing '//' caused a
    regression reported in bug #695699. This commit disables the
    optimization for expressions of the form '//foo[predicate]'.
-----------------------------------------

What I did:

1) I downloaded libxml2 from git (Upstream: HEAD)
2) I then retagged libxml2 to a certain commit (starting at 2.9.1)
3) I then grabbed one commit after another, recompiled, reinstalled and tested

The above optimization is the issue of xpath fails. Hope I was able to help and would like to see it fixed if possible.

Comment 5 Nick Wellnhofer 2016-07-27 15:51:02 UTC
The behavior of libxml2 2.9.2 is correct (and should also match the behavior of 2.9.0 and previous versions). The only broken version is 2.9.1. An expression of the form //title[1] should really return the first title child of every node containing titles. If you want the first title in the whole document, try (//title)[1].

Comment 6 Ali Akcaagac 2016-07-27 16:11:33 UTC
Interesting!

This means - if I understand it correctly - the correct way is that //title[1] returns not just the first element but also all first elements down the tree (of all the children and siblings that may follow).

Thanks for the feedback then. I wondered and thought this to be a bug because one of my scripts failed to work (written around the 2.9.1 release date back in 2013).

Will adopt your suggestion with (//tile)[1] then.

Thanks for the feedback.

Comment 7 Ali Akcaagac 2016-07-27 16:15:19 UTC
This works... Thanks! Gonna close the report!


Note You need to log in before you can comment on or make changes to this bug.