From 402826a1069c41fb8d80b91d48a19991a9ad1db2 Mon Sep 17 00:00:00 2001 From: Davide Brunato Date: Tue, 17 Dec 2019 14:56:17 +0100 Subject: [PATCH] Fix double slash shortcut token (issue #14) --- elementpath/xpath1_parser.py | 2 +- tests/test_xpath1_parser.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/elementpath/xpath1_parser.py b/elementpath/xpath1_parser.py index eeaf5971..6337f746 100644 --- a/elementpath/xpath1_parser.py +++ b/elementpath/xpath1_parser.py @@ -756,7 +756,7 @@ def select(self, context=None): for elem in self[0].select(context): if not is_element_node(elem): self.wrong_type("left operand must returns element nodes: %r" % elem) - for _ in context.iter_descendants(item=elem, axis='descendant-or-self'): + for _ in context.iter_descendants(item=elem): for result in self[1].select(context): yield result diff --git a/tests/test_xpath1_parser.py b/tests/test_xpath1_parser.py index 29016b43..1c2dbb45 100644 --- a/tests/test_xpath1_parser.py +++ b/tests/test_xpath1_parser.py @@ -997,15 +997,32 @@ def test_descendant_axis(self): self.check_selector('/descendant::node()', root, [e for e in root.iter()]) def test_descendant_or_self_axis(self): + root = self.etree.XML('') + self.check_selector('descendant-or-self::node()', root, [e for e in root.iter()]) + self.check_selector('descendant-or-self::node()/.', root, [e for e in root.iter()]) + + def test_double_slash_shortcut(self): root = self.etree.XML('') self.check_selector('//.', root, [e for e in root.iter()]) self.check_selector('/A//.', root, [e for e in root.iter()]) + self.check_selector('/A//self::node()', root, [e for e in root.iter()]) self.check_selector('//C1', root, [root[2][1]]) self.check_selector('//B2', root, [root[1]]) self.check_selector('//C', root, [root[0][0], root[2][0]]) self.check_selector('//*', root, [e for e in root.iter()]) - self.check_selector('descendant-or-self::node()', root, [e for e in root.iter()]) - self.check_selector('descendant-or-self::node()/.', root, [e for e in root.iter()]) + + # Issue #14 + root = self.etree.XML(""" + + + + + + + + """) + + self.check_selector('/pm/content/pmEntry/pmEntry//pmEntry[@pmEntryType]', root, []) def test_following_axis(self): root = self.etree.XML('')