changeset 384:5b6e4335ee21 trunk

Fix for infinite loop in XPath test. Closes #82.
author cmlenz
date Mon, 04 Dec 2006 19:00:46 +0000
parents e17b84835b0f
children e72bd8515dd2
files genshi/path.py genshi/tests/path.py
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 \
--- a/genshi/tests/path.py
+++ b/genshi/tests/path.py
@@ -438,6 +438,19 @@
         self.assertEqual('<foo xmlns="FOO">bar</foo>',
                          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 <http://genshi.edgewall.org/ticket/82>.
+        """
+        xml = XML('<ul flag="1"><li>a</li><li>b</li></ul>')
+        path = Path('.[@flag="1"]/*')
+        self.assertEqual('<li>a</li><li>b</li>', path.select(xml).render())
+
+        xml = XML('<ul flag="1"><li>a</li><li>b</li></ul>')
+        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
Copyright (C) 2012-2017 Edgewall Software