XPathEvaluator namespaces regression in 3.6.3+

Bug #1617612 reported by pdknsk
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Invalid
Undecided
Unassigned

Bug Description

This code used to work.

lxml.etree : (3, 6, 2, 0)
libxml used : (2, 9, 1)
libxml compiled : (2, 9, 1)
libxslt used : (1, 1, 28)
libxslt compiled : (1, 1, 28)

>>> xml = etree.XML('<Response xmlns="http://example.com"><Code>200</Code></Response>')
>>> xpath = etree.XPathEvaluator(xml, namespaces = {'1': xml.nsmap[None]})
>>> xpath('//1:Code/text()')
['200']

It throws an exception now.

lxml.etree : (3, 6, 3, 0)
libxml used : (2, 9, 4)
libxml compiled : (2, 9, 4)
libxslt used : (1, 1, 29)
libxslt compiled : (1, 1, 29)

>>> xpath('//1:Code/text()')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "src/lxml/xpath.pxi", line 307, in lxml.etree.XPathElementEvaluator.__call__ (src/lxml/lxml.etree.c:167085)
  File "src/lxml/xpath.pxi", line 227, in lxml.etree._XPathEvaluatorBase._handle_result (src/lxml/lxml.etree.c:166044)
lxml.etree.XPathEvalError: Invalid expression

Revision history for this message
scoder (scoder) wrote :

XML names must not start with a digit. That includes namespace prefixes. It seems that libxml2 got stricter here in recent versions, although I have no idea why that wasn't an error before. Seems like an unusual bug to allow that in the first place.

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.