# HG changeset patch # User cmlenz # Date 1165258846 0 # Node ID 5b6e4335ee2192824f8af40b9346d539db0bead2 # Parent e17b84835b0ffd944c6f7505660677df51416d12 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('
  • a
  • b
  • ', 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