From: Armin Ronacher Date: Sun, 8 Jan 2017 10:21:32 +0000 (+0100) Subject: Support new scoping rules in scoped blocks X-Git-Tag: 2.9.3~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1a56de18a8865a3b76299109d01ff4087e30690;p=thirdparty%2Fjinja.git Support new scoping rules in scoped blocks --- diff --git a/CHANGES b/CHANGES index fac3b8d3..8a160d79 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,9 @@ Version 2.9.3 intended behavior in all situations however it does not restore the old behavior where limited assignments to outer scopes was possible. For more information and a discussion see #641 +- Resolved an issue where `block scoped` would not take advantage of the + new scoping rules. In some more exotic cases a variable overriden in a + local scope would not make it into a block. Version 2.9.2 ------------- diff --git a/jinja2/runtime.py b/jinja2/runtime.py index 958ddfd4..5c2089b8 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -214,10 +214,12 @@ class Context(object): 'StopIteration exception') def derived(self, locals=None): - """Internal helper function to create a derived context.""" + """Internal helper function to create a derived context. This is + used in situations where the system needs a new context in the same + template that is independent. + """ context = new_context(self.environment, self.name, {}, - self.parent, True, None, locals) - context.vars.update(self.vars) + self.get_all(), True, None, locals) context.eval_ctx = self.eval_ctx context.blocks.update((k, list(v)) for k, v in iteritems(self.blocks)) return context diff --git a/tests/test_regression.py b/tests/test_regression.py index fe16edee..1706c8b5 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -447,3 +447,8 @@ class TestBug(object): t = env.from_string('{% macro x() %}{% block foo %}x{% ' 'endblock %}{% endmacro %}{{ x() }}') assert t.render() == 'x' + + def test_scoped_block(self, env): + t = env.from_string('{% set x = 1 %}{% with x = 2 %}{% block y scoped %}' + '{{ x }}{% endblock %}{% endwith %}') + assert t.render() == '2'