Skip to content

Commit

Permalink
Fix XPath 2.0 comparison operators with XSD 1.1 datatypes
Browse files Browse the repository at this point in the history
  - Restore old code and add a regression test
  • Loading branch information
brunato committed Jan 30, 2021
1 parent bb1455f commit 62584c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions elementpath/xpath2/xpath2_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,8 @@ def evaluate(self, context=None):
operands[0] = float(operands[0])
elif all(isinstance(x, Duration) for x in operands) and self.symbol in ('eq', 'ne'):
pass
elif (issubclass(cls0, cls1) or issubclass(cls1, cls0)) and not issubclass(cls0, Duration):
pass
else:
msg = "cannot apply {} between {!r} and {!r}".format(self, *operands)
raise self.error('XPTY0004', msg)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_xpath2_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ def test_comparison_operators(self):
self.check_value('xs:duration("P31D") ne xs:yearMonthDuration("P1M")', True)
self.wrong_type('QName("", "ncname") le QName("", "ncname")', 'XPTY0004')

# From W3C XSD 1.1 tests
context = XPathContext(root=self.etree.XML('<root/>'),
variables={'value': Date(9999, 10, 10)})
self.check_value('$value lt current-date()', False, context=context)

def test_comparison_in_expression(self):
context = XPathContext(self.etree.XML('<value>false</value>'))
self.check_value("(. = 'false') = (. = 'false')", True, context)
Expand Down

0 comments on commit 62584c7

Please sign in to comment.