changeset 945:d1edb246cc61 trunk

Fix out-by-one error introduced in r1097 that led to match templates missing the last event from the stream they were processing.
author hodgestar
date Tue, 30 Aug 2011 12:48:57 +0000
parents 657f9ecffa3c
children 0f9fe59dfa00
files genshi/template/markup.py genshi/template/tests/directives.py
diffstat 2 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/genshi/template/markup.py
+++ b/genshi/template/markup.py
@@ -385,10 +385,11 @@
                         for event in content:
                             pass
 
-                    # Let the remaining match templates know about the last
-                    # event in the matched content, so they can update their
+                    # Let this match template and the remaining match
+                    # templates know about the last event in the
+                    # matched content, so they can update their
                     # internal state accordingly
-                    for test in [mt[0] for mt in match_templates[idx + 1:]]:
+                    for test in [mt[0] for mt in match_templates[idx:]]:
                         test(tail[0], namespaces, ctxt, updateonly=True)
 
                     break
--- a/genshi/template/tests/directives.py
+++ b/genshi/template/tests/directives.py
@@ -1005,6 +1005,27 @@
           </body>
         </html>""", tmpl.generate().render())
 
+    def test_match_multiple_times3(self):
+        # See http://genshi.edgewall.org/ticket/370#comment:12
+        tmpl = MarkupTemplate("""<?xml version="1.0"?>
+          <root xmlns:py="http://genshi.edgewall.org/">
+            <py:match path="foo/bar">
+              <zzzzz/>
+            </py:match>
+            <foo>
+              <bar/>
+              <bar/>
+            </foo>
+            <bar/>
+          </root>""")
+        self.assertEqual("""<?xml version="1.0"?>\n<root>
+            <foo>
+              <zzzzz/>
+              <zzzzz/>
+            </foo>
+            <bar/>
+          </root>""", tmpl.generate().render())
+
     # FIXME
     #def test_match_after_step(self):
     #    tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
Copyright (C) 2012-2017 Edgewall Software