Should set blocks be safe by default?
See original GitHub issueRight now this testcase would fail:
def test_set_block(self):
env = Environment(extensions=['jinja2.ext.autoescape'],
autoescape=True)
tmpl = env.from_string('{% set foo %}<br>{% endset %}{{ foo }}')
assert tmpl.render() == '<br>'
> assert tmpl.render() == '<br>'
E assert '<br>' == '<br>'
E - <br>
E + <br>
The contents of a set block is very similar to a macro though, so I think this behavior is not what you’d expect. Especially since you easily get double escaping, as shown in an extended version of the testcase above:
def test_set_block(self):
env = Environment(extensions=['jinja2.ext.autoescape'],
autoescape=True)
tmpl = env.from_string('{% set foo %}{{ bar }}<br>{% endset %}'
'{{ foo }}')
> assert tmpl.render(bar='<hr>') == '<hr><br>'
E assert '&lt;hr&gt;<br>' == '<hr><br>'
E - &lt;hr&gt;<br>
E + <hr><br>
If I add the safe
filter to my set block (added in #489) the testcase passes fine, but I think this is the most common use case and thus shouldn’t require a filter.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Manage your allows and blocks in the Tenant Allow/Block List
By default, block entries for domains and email addresses, files and URLs expire after 30 days, but you can set them to expire...
Read more >Block connections to your Mac with a firewall - Apple Support
On your Mac, choose Apple menu > System Settings, click Network in the sidebar, then click Firewall. (You may need to scroll down.)....
Read more >Change site permissions - Computer - Google Chrome Help
You can set permissions for a website without changing your default settings. ... The site will use its settings instead of the default...
Read more >World border - Minecraft Wiki - Fandom
Sets the number of blocks a player may safely be outside the world border before taking damage. The default is 5 blocks. /worldborder...
Read more >Default and custom security groups - AWS Documentation
A security group name must be unique for the VPC. The following are the default rules for a security group that you create:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks Armin!
I just hit this issue as well.
My workaround: