cpython: 56a4561600ad (original) (raw)

Mercurial > cpython

changeset 81681:56a4561600ad

Issue #12323: Strengthen error checking of the position XPath selectors [#12323]

Eli Bendersky eliben@gmail.com
date Thu, 24 Jan 2013 06:29:26 -0800
parents 2c12a1236fdc
children c6b0b96451c6 0c9268ac3ffa
files Lib/test/test_xml_etree.py Lib/xml/etree/ElementPath.py
diffstat 2 files changed, 12 insertions(+), 2 deletions(-)[+] [-] Lib/test/test_xml_etree.py 5 Lib/xml/etree/ElementPath.py 9

line wrap: on

line diff

--- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -1793,6 +1793,11 @@ class ElementFindTest(unittest.TestCase) self.assertEqual(e.find('./tag[last()-1]').attrib['class'], 'c') self.assertEqual(e.find('./tag[last()-2]').attrib['class'], 'b')

+ def test_findall(self): e = ET.XML(SAMPLE_XML) e[2] = ET.XML(SAMPLE_SECTION)

--- a/Lib/xml/etree/ElementPath.py +++ b/Lib/xml/etree/ElementPath.py @@ -174,7 +174,7 @@ def prepare_predicate(next, token): if elem.get(key) == value: yield elem return select

@@ -182,7 +182,7 @@ def prepare_predicate(next, token): if elem.find(tag) is not None: yield elem return select

@@ -196,7 +196,10 @@ def prepare_predicate(next, token): if signature == "-" or signature == "-()" or signature == "-()-": # [index] or [last()] or [last()-index] if signature == "-":

@@ -205,6 +208,8 @@ def prepare_predicate(next, token): index = int(predicate[2]) - 1 except ValueError: raise SyntaxError("unsupported expression")