[Django] #34574: Extend docs for `autoescape` and `escape` with examples using filters that operate with sequences

15 views
Skip to first unread message

Django

unread,
May 18, 2023, 9:50:44 AM5/18/23
to django-...@googlegroups.com
#34574: Extend docs for `autoescape` and `escape` with examples using filters that
operate with sequences
-------------------------------------------+------------------------
Reporter: Natalia Bidart | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
Following a recent report, it has come to out attention that the docs for
`autoescape` and `escape` could be improved by explicitly mentioning how
those interact with the results of applying (chaining) filters that would
mark their result as safe (like those that operate with sequences). For
example, in this code:

{{{
{% 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.

Django

unread,
May 18, 2023, 12:05:15 PM5/18/23
to django-...@googlegroups.com
#34574: Extend docs for `autoescape` and `escape` with examples using filters that
operate with sequences
--------------------------------------+------------------------------------

Reporter: Natalia Bidart | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Template system | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:1>

Django

unread,
May 18, 2023, 1:03:38 PM5/18/23
to django-...@googlegroups.com
#34574: Extend docs for `autoescape` and `escape` with examples using filters that
operate with sequences
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Natalia
Type: | Bidart
Cleanup/optimization | Status: assigned

Component: Template system | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* owner: nobody => Natalia Bidart
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:2>

Django

unread,
May 18, 2023, 9:24:49 PM5/18/23
to django-...@googlegroups.com
#34574: Extend docs for `autoescape` and `escape` with examples using filters that
operate with sequences
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Natalia
Type: | Bidart
Cleanup/optimization | Status: assigned
Component: Template system | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/16871 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:3>

Django

unread,
May 26, 2023, 12:28:00 AM5/26/23
to django-...@googlegroups.com
#34574: Extend docs for `autoescape` and `escape` with examples using filters that
operate with sequences
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Natalia
Type: | Bidart
Cleanup/optimization | Status: assigned
Component: Template system | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34574#comment:4>

Django

unread,
May 26, 2023, 1:49:38 AM5/26/23
to django-...@googlegroups.com
#34574: Extend docs for `autoescape` and `escape` with examples using filters that
operate with sequences
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Natalia
Type: | Bidart
Cleanup/optimization | Status: closed

Component: Template system | Version: 4.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
May 26, 2023, 1:49:39 AM5/26/23
to django-...@googlegroups.com
#34574: Extend docs for `autoescape` and `escape` with examples using filters that
operate with sequences
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Natalia
Type: | Bidart
Cleanup/optimization | Status: closed
Component: Template system | Version: 4.2
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* 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>

Django

unread,
May 26, 2023, 1:51:35 AM5/26/23
to django-...@googlegroups.com
#34574: Extend docs for `autoescape` and `escape` with examples using filters that
operate with sequences
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Natalia
Type: | Bidart
Cleanup/optimization | Status: closed
Component: Template system | Version: 4.2
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages