Skip to content

Commit

Permalink
Fix double slash shortcut token (issue #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Dec 17, 2019
1 parent 1e25c91 commit 402826a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion elementpath/xpath1_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 19 additions & 2 deletions tests/test_xpath1_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<A><B1><C/></B1><B2/><B3><C/><C1/></B3></A>')
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('<A><B1><C/></B1><B2/><B3><C/><C1/></B3></A>')
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("""
<pm>
<content>
<pmEntry>
<pmEntry pmEntryType="pm001">
</pmEntry>
</pmEntry>
</content>
</pm>""")

self.check_selector('/pm/content/pmEntry/pmEntry//pmEntry[@pmEntryType]', root, [])

def test_following_axis(self):
root = self.etree.XML('<A><B1><C1/></B1><B2/><B3><C1/><C2/></B3><B4><C1><D1/></C1></B4></A>')
Expand Down

0 comments on commit 402826a

Please sign in to comment.