# HG changeset patch # User cmlenz # Date 1158925224 0 # Node ID fe8dbe9066c18b06e372d1e84f10d13a8b363805 # Parent da3a27589559640c5552298ea5dd5d9ab664c2a7 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. diff --git a/genshi/path.py b/genshi/path.py --- 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 diff --git a/genshi/tests/path.py b/genshi/tests/path.py --- a/genshi/tests/path.py +++ b/genshi/tests/path.py @@ -230,10 +230,10 @@ self.assertEqual('', path.select(xml).render()) def test_simple_union(self): - xml = XML('Oh my') + xml = XML("""1
2
3
""") path = Path('*|text()') self.assertEqual('', repr(path)) - self.assertEqual('Oh my', path.select(xml).render()) + self.assertEqual('1
2
3
', path.select(xml).render()) def test_predicate_name(self): xml = XML('')