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
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)
'{% endautoescape %}{{ x }}{{ "<y>" }}')
assert tmpl.render(x=1) == '<x>1<y>'
+ 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()