XPath evaluation should throw exception when expression starts with triple slashes
I noticed a standard-incompliant detail in the xpath() function of the Python lxml module. According to the lxml team, this would have to be fixed in libxml2: https://bugs.launchpad.net/lxml/+bug/1861100
xpath() accepts an expression that starts with triple slashes. I would expect it to raise an XPathEvalError instead.
>>> from lxml import etree
>>> x = etree.fromstring('<root><a/></root>')
>>> x.xpath('///a')
[<Element a at 0x1e7fc2a4a48>]
Starting with triple slashes is not allowed according to the grammar standardized in "XML Path Language (XPath) Version 1.0". The grammar tester applet at http://www.w3.org/2013/01/qt-applets/xpath1/ also rejects such expressions. I tested four online XPath checkers (e.g. http://xpather.com), they don't accept leading triple slashes either.
Python : sys.version_info(major=3, minor=7, micro=4, releaselevel='final', serial=0)
lxml.etree : (4, 3, 1, 0)
libxml used : (2, 9, 5)
libxml compiled : (2, 9, 5)
libxslt used : (1, 1, 30)
Edited by Daniel Herding