Skip to content
Myr

Added another testcase and fixed a bug with the volatile scoping.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent d3e6bc4 · Browse files · 2 files+15 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−1 removed

  • other:+15 added−1 removed

2 files+15 added−1 removed

modified:jinja2/testsuite/ext.py+13 added
304 unmodified lines
305 tmpl = env.from_string('{% autoescape true %}{% set x = "<x>" %}{{ x }}'306 '{% endautoescape %}{{ x }}{{ "<y>" }}')307 assert tmpl.render(x=1) == '&lt;x&gt;1<y>'308309 def test_volatile_scoping(self):310 env = Environment(extensions=['jinja2.ext.autoescape'])311 tmpl = env.from_string('''312 {% autoescape val %}313 {% macro foo(x) %}314 [{{ x }}]315 {% endmacro %}316 {{ foo().__class__.__name__ }}317 {% endautoescape %}318 ''')319 assert tmpl.render(val=True).strip() == 'Markup'320 assert tmpl.render(val=False).strip() == unicode.__name__321322323def suite():324 suite = unittest.TestSuite()325 suite.addTest(unittest.makeSuite(ExtensionsTestCase))326 suite.addTest(unittest.makeSuite(InternationalizationTestCase))
2 unmodified lines
modified:jinja2/compiler.py+2 added-1 removed
1316 unmodified lines
1317 close = 01318 if frame.eval_ctx.volatile:1319 self.write('(context.eval_ctx.autoescape and'1320 ' escape or to_string)(')1321 close += 11322 elif frame.eval_ctx.autoescape:1323 self.write('escape(')1324 close += 11325 if self.environment.finalize is not None:
287 unmodified lines
1613 self.visit(keyword.value, frame)1614 try:1615 val = keyword.value.as_const(frame.eval_ctx)1616 except nodes.Impossible:1616 frame.volatile = True1617 frame.eval_ctx.volatile = True1618 else:1619 setattr(frame.eval_ctx, keyword.key, val)16201621 def visit_ScopedEvalContextModifier(self, node, frame):
8 unmodified lines