The `upper` template filter should set `is_safe=True`
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<P>H... world!</p>\n' == '\n<P>HELLO W... world!</P>\n'
E
E
E - <P>HELLO WORLD!</P>
E + <P>HELLO WORLD!</P>
E <p>hello world!</p>
Change History
(6)
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Component: |
Uncategorized → Template system
|
Triage Stage: |
Unreviewed → Accepted
|
Type: |
Uncategorized → Bug
|
Owner: |
set to Chaitanya Rahalkar
|
Status: |
new → assigned
|
Needs documentation: |
set
|
Patch needs improvement: |
set
|
See https://github.com/django/django/pull/18988