{{{
{% autoescape off %}
{{ some_list|join:","|escape }}
{% endautoescape %}
}}}
the string resulting from the concatenation of `some_list` items would not
be escaped. The reason is that `join` returns a string marked as safe (but
since it was executed in the context of `autoescape` being off, each
individual item is not escaped), and the `escape` docs mention the
following (but they could use an example to make the point more obvious):
{{{
Applying escape to a variable that would normally have auto-escaping
applied to the result will only result in one round of escaping being
done.
}}}
Similarly, the `safe` docs also refers to the above (but again,
explicitness could go long way here):
{{{
If you are chaining filters, a filter applied after safe can make the
contents unsafe again. For example, the following code prints the variable
as is, unescaped:
{{ var|safe|escape }}
}}}
which is analogous to what is happening in the first code snippet: `join`
is marking the result as safe, so the chained `|escape` does nothing.
--
Ticket URL: <https://code.djangoproject.com/ticket/34574>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:1>
* owner: nobody => Natalia Bidart
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/16871 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:4>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"881cc139e2d53cc1d3ccea7f38faa960f9e56597" 881cc13]:
{{{
#!CommitTicketReference repository=""
revision="881cc139e2d53cc1d3ccea7f38faa960f9e56597"
Refs #34574, Refs #34577 -- Mentioned escapeseq filter in
escape/autoescape docs.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"1a59a324cec5caf12ea0c4947564828aa7bda02a" 1a59a32]:
{{{
#!CommitTicketReference repository=""
revision="1a59a324cec5caf12ea0c4947564828aa7bda02a"
Fixed #34574 -- Noted unexpected outcomes in autoescape/escape docs.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"25bd9faf327c7c0a45b9ca6e0ea678d898af8838" 25bd9fa]:
{{{
#!CommitTicketReference repository=""
revision="25bd9faf327c7c0a45b9ca6e0ea678d898af8838"
[4.2.x] Fixed #34574 -- Noted unexpected outcomes in autoescape/escape
docs.
Backport of 1a59a324cec5caf12ea0c4947564828aa7bda02a from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:7>