From b9655a457daacd33d179f39dd8c19a9533bdd7d2 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 6 Jan 2017 14:29:23 +0100 Subject: Set macro autoescape behavior at call instead of compile time. Fixes #565 --- tests/test_ext.py | 8 ++++++++ tests/test_security.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_ext.py b/tests/test_ext.py index a870d5b5..9a5bdfd6 100644 --- a/tests/test_ext.py +++ b/tests/test_ext.py @@ -355,6 +355,14 @@ class TestNewstyleInternationalization(): assert t.render(ae=True) == 'Wert: <test>' assert t.render(ae=False) == 'Wert: ' + def test_autoescape_macros(self): + env = Environment(autoescape=False, extensions=['jinja2.ext.autoescape']) + template = ( + '{% macro m() %}{% endmacro %}' + '{% autoescape true %}{{ m() }}{% endautoescape %}' + ) + assert env.from_string(template).render() == '' + def test_num_used_twice(self): tmpl = newstyle_i18n_env.get_template('ngettext_long.html') assert tmpl.render(apples=5, LANGUAGE='de') == u'5 Äpfel' diff --git a/tests/test_security.py b/tests/test_security.py index c0442ce7..f0edd881 100644 --- a/tests/test_security.py +++ b/tests/test_security.py @@ -16,6 +16,7 @@ from jinja2.sandbox import SandboxedEnvironment, \ from jinja2 import Markup, escape from jinja2.exceptions import SecurityError, TemplateSyntaxError, \ TemplateRuntimeError +from jinja2.nodes import EvalContext from jinja2._compat import text_type @@ -119,7 +120,10 @@ class TestSandbox(): assert text_type(t.module) == escaped_out assert escape(t.module) == escaped_out assert t.module.say_hello('foo') == escaped_out - assert escape(t.module.say_hello('foo')) == escaped_out + assert escape(t.module.say_hello( + EvalContext(env), 'foo')) == escaped_out + assert escape(t.module.say_hello( + 'foo')) == escaped_out def test_attr_filter(self, env): env = SandboxedEnvironment() -- cgit v1.2.3