Skip to content
Myr

Block sets are now safe. This fixes #490

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent e273b3a · Browse files · 3 files+9 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+9 added−1 removed

  • tests:+6 added−0 removed
  • other:+3 added−1 removed

3 files+9 added−1 removed

modified:jinja2/compiler.py+2 added-1 removed
1295 unmodified lines
1296 self.buffer(block_frame)1297 self.blockvisit(node.body, block_frame)1298 self.newline(node)1299 self.visit(node.target, frame)1300 self.write(' = concat(%s)' % block_frame.buffer)1300 self.write(' = (Markup if context.eval_ctx.autoescape '1301 'else identity)(concat(%s))' % block_frame.buffer)1302 self.pop_assign_tracking(frame)1303 self.leave_frame(block_frame)13041305 # -- Expression Visitors
288 unmodified lines
modified:tests/test_core_tags.py+6 added
346 unmodified lines
347 def test_block(self, env_trim):348 tmpl = env_trim.from_string('{% set foo %}42{% endset %}{{ foo }}')349 assert tmpl.render() == '42'350 assert tmpl.module.foo == u'42'351352 def test_block_escaping(self):353 env = Environment(autoescape=True)354 tmpl = env.from_string('{% set foo %}<em>{{ test }}</em>'355 '{% endset %}foo: {{ foo }}')356 assert tmpl.render(test='<unsafe>') == 'foo: <em>&lt;unsafe&gt;</em>'
modified:CHANGES+1 added
25 unmodified lines
26- Change the logic for macro autoescaping to be based on the runtime27 autoescaping information at call time instead of macro define time.28- Ported a modified version of the `tojson` filter from Flask to Jinja229 and hooked it up with the new policy framework.30- Block sets are now marked `safe` by default.3132Version 2.8.233-------------34
381 unmodified lines