changeset 259:fe8dbe9066c1 trunk

Fix bug in evaluating XPath expressions using the union operator `|`, which caused any path but the first to get out of sync with the event stream, and the whole thing returning too few results.
author cmlenz
date Fri, 22 Sep 2006 11:40:24 +0000
parents da3a27589559
children e14a41120be7
files genshi/path.py genshi/tests/path.py
diffstat 2 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/genshi/path.py
+++ b/genshi/path.py
@@ -157,6 +157,7 @@
         paths = [(p, len(p), [0], [], [0] * len(p)) for p in self.paths]
 
         def _test(kind, data, pos, namespaces, variables):
+            retval = None
             for steps, size, cursors, cutoff, counter in paths:
 
                 # Manage the stack that tells us "where we are" in the stream
@@ -166,7 +167,8 @@
                     continue
                 elif kind is START:
                     cursors.append(cursors and cursors[-1] or 0)
-                elif not cursors:
+
+                if retval or not cursors:
                     continue
                 cursor = cursors[-1]
                 depth = len(cursors)
@@ -176,7 +178,7 @@
 
                 ctxtnode = not ignore_context and kind is START \
                                               and depth == 2
-                matched = retval = None
+                matched = None
                 while 1:
                     # Fetch the next location step
                     axis, nodetest, predicates = steps[cursor]
@@ -262,8 +264,7 @@
                         break
                     cursors[-1] = cursor
 
-                if retval:
-                    return retval
+            return retval
 
         return _test
 
--- a/genshi/tests/path.py
+++ b/genshi/tests/path.py
@@ -230,10 +230,10 @@
         self.assertEqual('<?php echo("x") ?>', path.select(xml).render())
 
     def test_simple_union(self):
-        xml = XML('<root>Oh <foo>my</foo></root>')
+        xml = XML("""<body>1<br />2<br />3<br /></body>""")
         path = Path('*|text()')
         self.assertEqual('<Path "child::*|child::text()">', repr(path))
-        self.assertEqual('Oh <foo>my</foo>', path.select(xml).render())
+        self.assertEqual('1<br/>2<br/>3<br/>', path.select(xml).render())
 
     def test_predicate_name(self):
         xml = XML('<root><foo/><bar/></root>')
Copyright (C) 2012-2017 Edgewall Software