Some string comparisson does not work inside an xpath expression

Bug #1785022 reported by Daniel Brosnan Blázquez
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Invalid
Undecided
Unassigned

Bug Description

When trying to compare two strings with an operator different than "=" the xpath does not evaluate properly, giving 0 results for structures which contain nodes that would be valid for the comparison expression. For example:
Given the following content of an xml
<nodes>
 <a>test</a>
 <b>test1</b>
</nodes>

and the following python code (attached for better access):
# Import python utilities
import argparse

# Import xml parser
from lxml import etree

if __name__ == "__main__":

    xml = etree.XML("<nodes><a>test</a><b>test1</b></nodes>")
    xpath_xml = etree.XPathEvaluator(xml)

    # Testing = operator
    test = xpath_xml("/nodes/child::*[text() = 'test']")

    assert len(test) == 1

    # Testing = operator
    test = xpath_xml("/nodes/child::*[text() = 'test1']")

    assert len(test) == 1

    # Testing > operator
    test = xpath_xml("/nodes/child::*[text() > 'test']")

    assert len(test) == 1

The python code fails to get the b node when the comparison is ">".

Is this a bug? or it is just not supported?
Note that the xpath evaluator does not raise any error.

Here the information requested for the investigation:
$ python3 lxml_info.py
Python : sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)
lxml.etree : (3, 3, 3, 0)
libxml used : (2, 9, 1)
libxml compiled : (2, 9, 1)
libxslt used : (1, 1, 28)
libxslt compiled : (1, 1, 28)

Thanks for you support.
Best regards.

Revision history for this message
Daniel Brosnan Blázquez (daniel.brosnan) wrote :
Revision history for this message
scoder (scoder) wrote :

XPath 1.0 does not support this. A PR for implementing this in ElementPath (perferably both in CPython and lxml) would be welcome.

"When neither object to be compared is a node-set and the operator is <=, <, >= or >, then the objects are compared by converting both objects to numbers and comparing the numbers according to IEEE 754. The < comparison will be true if and only if the first number is less than the second number. The <= comparison will be true if and only if the first number is less than or equal to the second number. The > comparison will be true if and only if the first number is greater than the second number. The >= comparison will be true if and only if the first number is greater than or equal to the second number."

https://www.w3.org/TR/1999/REC-xpath-19991116/#booleans

Changed in lxml:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.