From: Armin Ronacher Date: Sun, 14 Mar 2010 23:26:05 +0000 (+0100) Subject: Added another testcase and fixed a bug with the volatile scoping. X-Git-Tag: 2.4~18 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=744bb0a3230e759146ed98c463b527ee652d80f0;p=jinja2.git Added another testcase and fixed a bug with the volatile scoping. --HG-- branch : trunk --- diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 5f355a9..3bc6d35 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -1318,6 +1318,7 @@ class CodeGenerator(NodeVisitor): if frame.eval_ctx.volatile: self.write('(context.eval_ctx.autoescape and' ' escape or to_string)(') + close += 1 elif frame.eval_ctx.autoescape: self.write('escape(') close += 1 @@ -1613,7 +1614,7 @@ class CodeGenerator(NodeVisitor): try: val = keyword.value.as_const(frame.eval_ctx) except nodes.Impossible: - frame.volatile = True + frame.eval_ctx.volatile = True else: setattr(frame.eval_ctx, keyword.key, val) diff --git a/jinja2/testsuite/ext.py b/jinja2/testsuite/ext.py index 09b2b85..f8458b1 100644 --- a/jinja2/testsuite/ext.py +++ b/jinja2/testsuite/ext.py @@ -306,6 +306,19 @@ class AutoEscapeTestCase(JinjaTestCase): '{% endautoescape %}{{ x }}{{ "" }}') assert tmpl.render(x=1) == '<x>1' + def test_volatile_scoping(self): + env = Environment(extensions=['jinja2.ext.autoescape']) + tmpl = env.from_string(''' + {% autoescape val %} + {% macro foo(x) %} + [{{ x }}] + {% endmacro %} + {{ foo().__class__.__name__ }} + {% endautoescape %} + ''') + assert tmpl.render(val=True).strip() == 'Markup' + assert tmpl.render(val=False).strip() == unicode.__name__ + def suite(): suite = unittest.TestSuite()