Permalink
Browse files

fixed a problem with having call blocks in outer scopes that

have an argument that is also used as local variable in an
inner frame [#360].

--HG--
branch : trunk
  • Loading branch information...
1 parent a586989 commit e0016f5c62437f29a569c1d4067f16af3085ced1 @mitsuhiko mitsuhiko committed Jan 14, 2010
Showing with 38 additions and 2 deletions.
  1. +3 −0 CHANGES
  2. +1 −1 jinja2/compiler.py
  3. +34 −1 tests/test_old_bugs.py
View
@@ -11,6 +11,9 @@ Version 2.3
- include tags are now able to select between multiple templates
and take the first that exists, if a list of templates is
given.
+- fixed a problem with having call blocks in outer scopes that
+ have an argument that is also used as local variable in an
+ inner frame [#360].
Version 2.2.1
-------------
View
@@ -327,7 +327,7 @@ def visit_For(self, node):
self.visit(node.iter)
def visit_CallBlock(self, node):
- for child in node.iter_child_nodes(exclude=('body',)):
+ for child in node.iter_child_nodes(exclude=('body', 'args')):
self.visit(child)
def visit_FilterBlock(self, node):
View
@@ -8,7 +8,7 @@
:copyright: (c) 2009 by the Jinja Team.
:license: BSD.
"""
-from jinja2 import Environment, DictLoader, TemplateSyntaxError
+from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError
env = Environment()
@@ -101,3 +101,36 @@ def test_stacked_locals_scoping_bug():
# endif
''')
assert t.render(a=0, b=False, c=42, d=42.0) == '1111C'
+
+
+def test_call_with_args():
+ t = Template("""{% macro dump_users(users) -%}
+ <ul>
+ {%- for user in users -%}
+ <li><p>{{ user.username|e }}</p>{{ caller(user) }}</li>
+ {%- endfor -%}
+ </ul>
+ {%- endmacro -%}
+
+ {% call(user) dump_users(list_of_user) -%}
+ <dl>
+ <dl>Realname</dl>
+ <dd>{{ user.realname|e }}</dd>
+ <dl>Description</dl>
+ <dd>{{ user.description }}</dd>
+ </dl>
+ {% endcall %}""")
+
+ assert [x.strip() for x in t.render(list_of_user=[{
+ 'username':'apo',
+ 'realname':'something else',
+ 'description':'test'
+ }]).splitlines()] == [
+ u'<ul><li><p>apo</p><dl>',
+ u'<dl>Realname</dl>',
+ u'<dd>something else</dd>',
+ u'<dl>Description</dl>',
+ u'<dd>test</dd>',
+ u'</dl>',
+ u'</li></ul>'
+ ]

0 comments on commit e0016f5

Please sign in to comment.