diff options
author | Armin Ronacher <armin.ronacher@active-4.com> | 2017-01-06 14:29:23 +0100 |
---|---|---|
committer | Armin Ronacher <armin.ronacher@active-4.com> | 2017-01-06 14:29:38 +0100 |
commit | b9655a457daacd33d179f39dd8c19a9533bdd7d2 (patch) | |
tree | cbfa2f590e30caee232fe7299e573ee5326f6ed5 /tests | |
parent | b3c174b31aec1ad30225e443dbccda872cdf94e2 (diff) | |
download | jinja-b9655a457daacd33d179f39dd8c19a9533bdd7d2.tar.gz |
Set macro autoescape behavior at call instead of compile time. Fixes #565
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_ext.py | 8 | ||||
-rw-r--r-- | tests/test_security.py | 6 |
2 files changed, 13 insertions, 1 deletions
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) == '<strong>Wert: <test></strong>' assert t.render(ae=False) == '<strong>Wert: <test></strong>' + def test_autoescape_macros(self): + env = Environment(autoescape=False, extensions=['jinja2.ext.autoescape']) + template = ( + '{% macro m() %}<html>{% endmacro %}' + '{% autoescape true %}{{ m() }}{% endautoescape %}' + ) + assert env.from_string(template).render() == '<html>' + 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('<blink>foo</blink>') == escaped_out - assert escape(t.module.say_hello('<blink>foo</blink>')) == escaped_out + assert escape(t.module.say_hello( + EvalContext(env), '<blink>foo</blink>')) == escaped_out + assert escape(t.module.say_hello( + '<blink>foo</blink>')) == escaped_out def test_attr_filter(self, env): env = SandboxedEnvironment() |