Fixed a macro scoping bug discovered by ckknight introduced in one of the earlier...
authorArmin Ronacher <armin.ronacher@active-4.com>
Thu, 30 Oct 2008 18:18:45 +0000 (19:18 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Thu, 30 Oct 2008 18:18:45 +0000 (19:18 +0100)
--HG--
branch : trunk

jinja2/compiler.py
tests/test_inheritance.py

index e6b2de0c429d54cb144146900552519d059caba7..5074a342ecbd11dd492636762ea1ac3117b7856f 100644 (file)
@@ -623,6 +623,8 @@ class CodeGenerator(NodeVisitor):
     def macro_body(self, node, frame, children=None):
         """Dump the function def of a macro or call block."""
         frame = self.function_scoping(node, frame, children)
+        # macros are delayed, they never require output checks
+        frame.require_output_check = False
         args = frame.arguments
         self.writeline('def macro(%s):' % ', '.join(args), node)
         self.indent()
index 8884b9f7ca997cfe0add3fd3ec76ae6c2aef3a96..bb86b4188611f2dd5d1083c688c65b38bd481def 100644 (file)
@@ -131,3 +131,38 @@ def test_multi_inheritance():
     assert tmpl.render(master='master2') == 'MASTER2CHILD'
     assert tmpl.render(master='master1') == 'MASTER1CHILD'
     assert tmpl.render() == 'MASTER1CHILD'
+
+
+def test_fixed_macro_scoping_bug():
+    assert Environment(loader=DictLoader({
+        'test.html': '''\
+    {% extends 'details.html' %}
+
+    {% macro my_macro() %}
+    my_macro
+    {% endmacro %}
+
+    {% block inner_box %}
+        {{ my_macro() }}
+    {% endblock %}
+        ''',
+        'details.html': '''\
+    {% extends 'standard.html' %}
+
+    {% macro my_macro() %}
+    my_macro
+    {% endmacro %}
+
+    {% block content %}
+        {% block outer_box %}
+            outer_box
+            {% block inner_box %}
+                inner_box
+            {% endblock %}
+        {% endblock %}
+    {% endblock %}
+    ''',
+        'standard.html': '''
+    {% block content %}&nbsp;{% endblock %}
+    '''
+    })).get_template("test.html").render().split() == [u'outer_box', u'my_macro']