You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Jinja, you can apply an escape filter on any string data multiple times, and it will not change the output, regardless as to whether auto escape is turned on or not:
>>> env = jinja2.Environment(autoescape=False);
>>> env.from_string("{% set val = '<a>' %}{% set var = val|e %}{{ var }}").render({})
u'<a>'
>>> env.from_string("{% set val = '<a>' %}{% set var = val|e %}{{ var|e }}").render({})
u'<a>'
>>> env = jinja2.Environment(autoescape=True);
>>> env.from_string("{% set var = '<a>' %}{% set val = var %}{{ val }}").render({})
u'<a>'
>>> env.from_string("{% set var = '<a>' %}{% set val = var|e %}{{ val }}").render({})
u'<a>'
>>> env.from_string("{% set var = '<a>' %}{% set val = var|e %}{{ val|e }}").render({})
u'<a>'
>>> env.from_string("{% set var = '<a>' %}{% set val = var|e %}{{ val|e|e|e }}").render({})
u'<a>'
You get the idea. Nunjucks, unfortunately, doesn't work this way:
> var env = new nj.Environment(new nj.FileSystemLoader(''), {'autoescape':false});
undefined
> env.renderString("{% set val = '<a>' %}{% set var = val|e %}{{ var }}");
'<a>'
> env.renderString("{% set val = '<a>' %}{% set var = val|e %}{{ var|e }}");
'&lt;a&gt;'
> var env = new nj.Environment(new nj.FileSystemLoader(''));
undefined
> env.renderString("{% set val = '<a>' %}{% set var = val|e %}{{ var }}");
'&lt;a&gt;'
> env.renderString("{% set val = '<a>' %}{% set var = val|e %}{{ var|e }}");
'&amp;lt;a&amp;gt;'
The problem seems to be that escaped strings are not immediately marked as safe after they are generated, but before they are returned. That would seem fix the problem:
> env.renderString("{% set val = '<a>' %}{% set var = val|e|safe %}{{ var|e|e|e|e }}");
'<a>'
A pull request will be forthcoming.
The text was updated successfully, but these errors were encountered:
legutierr
pushed a commit
to legutierr/nunjucks
that referenced
this issue
Mar 17, 2016
In Jinja, you can apply an escape filter on any string data multiple times, and it will not change the output, regardless as to whether auto escape is turned on or not:
You get the idea. Nunjucks, unfortunately, doesn't work this way:
The problem seems to be that escaped strings are not immediately marked as safe after they are generated, but before they are returned. That would seem fix the problem:
A pull request will be forthcoming.
The text was updated successfully, but these errors were encountered: