]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Support new scoping rules in scoped blocks
authorArmin Ronacher <armin.ronacher@active-4.com>
Sun, 8 Jan 2017 10:21:32 +0000 (11:21 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Sun, 8 Jan 2017 10:21:32 +0000 (11:21 +0100)
CHANGES
jinja2/runtime.py
tests/test_regression.py

diff --git a/CHANGES b/CHANGES
index fac3b8d3b55d8647352cabf8f008d9fac725e682..8a160d79a55b888464ef13899af0ba4a2f1f1e93 100644 (file)
--- 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
 -------------
index 958ddfd426b91b96b88113a0ed4483261748754e..5c2089b8c0a6206a8ed0465cd418e3008b32c748 100644 (file)
@@ -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
index fe16edeef1c2f634d269bc41112d1f16cce73d7b..1706c8b51001bde38a39c5908ef0b6035e3e21f4 100644 (file)
@@ -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'