diff genshi/path.py @ 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 6a809835cf62
children 24b3cbbc1b1b
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
 
Copyright (C) 2012-2017 Edgewall Software