# HG changeset patch
# User cmlenz
# Date 1165258846 0
# Node ID 1596045ff0f3fc72a401ef3123638b27e6051dfb
# Parent 9f5a34ac1d908330cf51e651988a347337dba699
Fix for infinite loop in XPath test. Closes #82.
diff --git a/genshi/path.py b/genshi/path.py
--- a/genshi/path.py
+++ b/genshi/path.py
@@ -244,8 +244,8 @@
# We're done with this step if it's the last step or the
# axis isn't "self"
- if last_step or not (axis is SELF or
- axis is DESCENDANT_OR_SELF):
+ if not matched or last_step or not (
+ axis is SELF or axis is DESCENDANT_OR_SELF):
break
if (retval or not matched) and kind is START and \
diff --git a/genshi/tests/path.py b/genshi/tests/path.py
--- a/genshi/tests/path.py
+++ b/genshi/tests/path.py
@@ -438,6 +438,19 @@
self.assertEqual('bar',
path.select(xml, namespaces=namespaces).render())
+ def test_predicate_termination(self):
+ """
+ Verify that a patch matching the self axis with a predicate doesn't
+ cause an infinite loop. See .
+ """
+ xml = XML('')
+ path = Path('.[@flag="1"]/*')
+ self.assertEqual('ab', path.select(xml).render())
+
+ xml = XML('')
+ path = Path('.[@flag="0"]/*')
+ self.assertEqual('', path.select(xml).render())
+
# FIXME: the following two don't work due to a problem in XML serialization:
# attributes that would need a namespace prefix that isn't in the
# prefix map would need to get an artificial prefix, but currently