[Django] #36049: The `upper` template filter should set `is_safe=True`

12 views
Skip to first unread message

Django

unread,
Jan 1, 2025, 10:25:48 AMJan 1
to django-...@googlegroups.com
#36049: The `upper` template filter should set `is_safe=True`
----------------------------+-----------------------------------------
Reporter: Lily Foote | Type: Uncategorized
Status: new | Component: Uncategorized
Version: 5.1 | 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
----------------------------+-----------------------------------------
I noticed this inconsistency between `upper` and `lower` where `upper` has
`is_safe=False` but `lower` has `is_safe=True`. I think `lower` is correct
and `upper` is incorrect.

This has been the case ever since `is_safe` was introduced in
https://github.com/django/django/commit/356662cf74c99fac90afb0f5e6aac8d2d573e62a.

{{{
from django.template import engines
from django.utils.safestring import mark_safe


def test_is_safe():
template = """
{{ html|upper }}
{{ html|lower }}
"""
template = engines["django"].from_string(template)
html = mark_safe("<p>Hello World!</p>")
assert template.render({"html": html}) == """
<p>HELLO WORLD!</p>
<p>hello world!</p>
"""

E AssertionError: assert '\n&lt;P&gt;H... world!</p>\n' ==
'\n<p>HELLO W... world!</p>\n'
E
E
E - <p>HELLO WORLD!</p>
E + &lt;P&gt;HELLO WORLD!&lt;/P&gt;
E <p>hello world!</p>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36049>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 1, 2025, 10:26:32 AMJan 1
to django-...@googlegroups.com
#36049: The `upper` template filter should set `is_safe=True`
-------------------------------+--------------------------------------
Reporter: Lily Foote | Owner: (none)
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Lily Foote:

Old description:

> I noticed this inconsistency between `upper` and `lower` where `upper`
> has `is_safe=False` but `lower` has `is_safe=True`. I think `lower` is
> correct and `upper` is incorrect.
>
> This has been the case ever since `is_safe` was introduced in
> https://github.com/django/django/commit/356662cf74c99fac90afb0f5e6aac8d2d573e62a.
>
> {{{
> from django.template import engines
> from django.utils.safestring import mark_safe
>

> def test_is_safe():
> template = """
> {{ html|upper }}
> {{ html|lower }}
> """
> template = engines["django"].from_string(template)
> html = mark_safe("<p>Hello World!</p>")
> assert template.render({"html": html}) == """
> <p>HELLO WORLD!</p>
> <p>hello world!</p>
> """
>
> E AssertionError: assert '\n&lt;P&gt;H... world!</p>\n' ==
> '\n<p>HELLO W... world!</p>\n'
> E
> E
> E - <p>HELLO WORLD!</p>
> E + &lt;P&gt;HELLO WORLD!&lt;/P&gt;
> E <p>hello world!</p>
> }}}

New description:

I noticed this inconsistency between `upper` and `lower` where `upper` has
`is_safe=False` but `lower` has `is_safe=True`. I think `lower` is correct
and `upper` is incorrect.

This has been the case ever since `is_safe` was introduced in
https://github.com/django/django/commit/356662cf74c99fac90afb0f5e6aac8d2d573e62a.

{{{
from django.template import engines
from django.utils.safestring import mark_safe


def test_is_safe():
template = """
{{ html|upper }}
{{ html|lower }}
"""
template = engines["django"].from_string(template)
html = mark_safe("<p>Hello World!</p>")
assert template.render({"html": html}) == """
<P>HELLO WORLD!</P>
<p>hello world!</p>
"""

E AssertionError: assert '\n&lt;P&gt;H... world!</p>\n' ==
'\n<p>HELLO W... world!</p>\n'
E
E
E - <P>HELLO WORLD!</P>
E + &lt;P&gt;HELLO WORLD!&lt;/P&gt;
E <p>hello world!</p>
}}}

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

Django

unread,
Jan 1, 2025, 10:27:28 AMJan 1
to django-...@googlegroups.com
'\n<P>HELLO W... world!</P>\n'
E
E
E - <P>HELLO WORLD!</P>
E + &lt;P&gt;HELLO WORLD!&lt;/P&gt;
E <p>hello world!</p>
}}}

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

Django

unread,
Jan 1, 2025, 9:43:14 PMJan 1
to django-...@googlegroups.com
#36049: The `upper` template filter should set `is_safe=True`
---------------------------------+------------------------------------
Reporter: Lily Foote | Owner: (none)
Type: Bug | Status: new
Component: Template system | Version: 5.1
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 Tim Graham):

* component: Uncategorized => Template system
* stage: Unreviewed => Accepted
* type: Uncategorized => Bug

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

Django

unread,
Jan 1, 2025, 11:53:47 PMJan 1
to django-...@googlegroups.com
#36049: The `upper` template filter should set `is_safe=True`
-------------------------------------+-------------------------------------
Reporter: Lily Foote | Owner: Chaitanya
| Rahalkar
Type: Bug | Status: assigned
Component: Template system | Version: 5.1
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 Chaitanya Rahalkar):

* owner: (none) => Chaitanya Rahalkar
* status: new => assigned

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

Django

unread,
Jan 2, 2025, 12:30:10 AMJan 2
to django-...@googlegroups.com
#36049: The `upper` template filter should set `is_safe=True`
-------------------------------------+-------------------------------------
Reporter: Lily Foote | Owner: Chaitanya
| Rahalkar
Type: Bug | Status: assigned
Component: Template system | Version: 5.1
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 Chaitanya Rahalkar):

* has_patch: 0 => 1

Comment:

See https://github.com/django/django/pull/18988
--
Ticket URL: <https://code.djangoproject.com/ticket/36049#comment:5>

Django

unread,
Jan 2, 2025, 3:56:50 AMJan 2
to django-...@googlegroups.com
#36049: The `upper` template filter should set `is_safe=True`
-------------------------------------+-------------------------------------
Reporter: Lily Foote | Owner: Chaitanya
| Rahalkar
Type: Bug | Status: assigned
Component: Template system | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1
* needs_docs: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36049#comment:6>

Django

unread,
Jan 6, 2025, 3:41:13 AMJan 6
to django-...@googlegroups.com
#36049: The `upper` template filter should set `is_safe=True`
-------------------------------------+-------------------------------------
Reporter: Lily Foote | Owner: Chaitanya
| Rahalkar
Type: Bug | Status: assigned
Component: Template system | Version: 5.1
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 Lily Foote):

* needs_better_patch: 1 => 0
* needs_docs: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36049#comment:7>

Django

unread,
Jan 6, 2025, 10:23:07 AMJan 6
to django-...@googlegroups.com
#36049: The `upper` template filter should set `is_safe=True`
-------------------------------------+-------------------------------------
Reporter: Lily Foote | Owner: Chaitanya
| Rahalkar
Type: Bug | Status: assigned
Component: Template system | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36049#comment:8>

Django

unread,
Jan 6, 2025, 11:22:42 AMJan 6
to django-...@googlegroups.com
#36049: The `upper` template filter should set `is_safe=True`
-------------------------------------+-------------------------------------
Reporter: Lily Foote | Owner: Chaitanya
| Rahalkar
Type: Bug | Status: assigned
Component: Template system | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_tests: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36049#comment:9>
Reply all
Reply to author
Forward
0 new messages