changeset 638:8bcd86cd6c10

Fix for descendant-or-self XPath patterns when namespaces are involved.
author cmlenz
date Mon, 17 Sep 2007 21:51:21 +0000
parents 93a19f09eebe
children b0cdc457dde9
files genshi/path.py genshi/tests/path.py
diffstat 2 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/genshi/path.py
+++ b/genshi/path.py
@@ -43,7 +43,8 @@
 import re
 
 from genshi.core import Stream, Attrs, Namespace, QName
-from genshi.core import START, END, TEXT, COMMENT, PI
+from genshi.core import START, END, TEXT, START_NS, END_NS, COMMENT, PI, \
+                        START_CDATA, END_CDATA
 
 __all__ = ['Path', 'PathSyntaxError']
 __docformat__ = 'restructuredtext en'
@@ -195,6 +196,9 @@
                     continue
                 elif kind is START:
                     cursors.append(cursors and cursors[-1] or 0)
+                elif kind is START_NS or kind is END_NS \
+                        or kind is START_CDATA or kind is END_CDATA:
+                    continue
 
                 if updateonly or retval or not cursors:
                     continue
@@ -272,6 +276,8 @@
                     if not matched or last_step or not (
                             axis is SELF or axis is DESCENDANT_OR_SELF):
                         break
+                    if ctxtnode and axis is DESCENDANT_OR_SELF:
+                        ctxtnode = False
 
                 if (retval or not matched) and kind is START and \
                         not (axis is DESCENDANT or axis is DESCENDANT_OR_SELF):
--- a/genshi/tests/path.py
+++ b/genshi/tests/path.py
@@ -76,7 +76,7 @@
         path = Path('//*')
         self.assertEqual('<Path "descendant-or-self::node()/child::*">',
                          repr(path))
-        self.assertEqual('<elem/>', path.select(xml).render())
+        self.assertEqual('<root><elem/></root>', path.select(xml).render())
 
     def test_1step_attribute(self):
         path = Path('@foo')
Copyright (C) 2012-2017 Edgewall Software