changeset 758:9f28d17b1f72 trunk

Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
author cmlenz
date Mon, 16 Jun 2008 09:22:21 +0000
parents 70a172ab5705
children 6a424a74f5be
files ChangeLog genshi/template/markup.py genshi/template/tests/markup.py
diffstat 3 files changed, 34 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,15 @@
  * Support for Python 2.3 has been dropped.
 
 
+Version 0.5.1
+http://svn.edgewall.org/repos/genshi/tags/0.5.1/
+(???, from branches/stable/0.5.x)
+
+ * Fix problem with nested match templates not being applied when buffering
+   on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the
+   problem and providing a test case!
+
+
 Version 0.5
 http://svn.edgewall.org/repos/genshi/tags/0.5.0/
 (Jun 9 2008, from branches/stable/0.5.x)
--- a/genshi/template/markup.py
+++ b/genshi/template/markup.py
@@ -221,7 +221,7 @@
         assert len(streams) == 1
         return streams[0]
 
-    def _match(self, stream, ctxt, match_templates=None, **vars):
+    def _match(self, stream, ctxt, match_templates=None, offset=0, **vars):
         """Internal stream filter that applies any defined match templates
         to the stream.
         """
@@ -254,6 +254,8 @@
 
             for idx, (test, path, template, hints, namespaces, directives) \
                     in enumerate(match_templates):
+                if idx < offset:
+                    continue
 
                 if test(event, namespaces, ctxt) is True:
                     if 'match_once' in hints:
@@ -296,7 +298,7 @@
                                     self._flatten(template, ctxt, **vars),
                                     ctxt, **vars),
                                 ctxt, **vars),
-                            ctxt, match_templates[idx + 1:], **vars):
+                            ctxt, match_templates, offset=idx + 1, **vars):
                         yield event
 
                     break
--- a/genshi/template/tests/markup.py
+++ b/genshi/template/tests/markup.py
@@ -687,6 +687,27 @@
         finally:
             shutil.rmtree(dirname)
 
+    def test_nested_matches_without_buffering(self):
+        xml = ("""<html xmlns:py="http://genshi.edgewall.org/">
+          <py:match path="body" once="true" buffer="false">
+            <body>
+              ${select('*|text')}
+              And some other stuff...
+            </body>
+          </py:match>
+          <body>
+            <span py:match="span">Foo</span>
+            <span>Bar</span>
+          </body>
+        </html>""")
+        tmpl = MarkupTemplate(xml, filename='test.html')
+        self.assertEqual("""<html>
+            <body>
+              <span>Foo</span>
+              And some other stuff...
+            </body>
+        </html>""", tmpl.generate().render())
+
 
 def suite():
     suite = unittest.TestSuite()
Copyright (C) 2012-2017 Edgewall Software