Opened 6 weeks ago

Last modified 6 weeks ago

#36049 assigned Bug

The `upper` template filter should set `is_safe=True`

Reported by: Lily Foote Owned by: Chaitanya Rahalkar
Component: Template system Version: 5.1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no
Pull Requests:18988

Description (last modified by Lily Foote)

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>

According to the ticket's flags, the next step(s) to move this issue forward are:

  • To add tests to the patch, then uncheck the "Needs tests" flag on the ticket.
  • To improve the patch as described in the pull request review comments or on this ticket, then uncheck "Patch needs improvement".
  • If creating a new pull request, include a link to the pull request in the ticket comment when making that update. The usual format is: [https://github.com/django/django/pull/#### PR].

Change History (9)

comment:1 by Lily Foote, 6 weeks ago

Description: modified (diff)

comment:2 by Lily Foote, 6 weeks ago

Description: modified (diff)

comment:3 by Tim Graham, 6 weeks ago

Component: UncategorizedTemplate system
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:4 by Chaitanya Rahalkar, 6 weeks ago

Owner: set to Chaitanya Rahalkar
Status: newassigned

comment:5 by Chaitanya Rahalkar, 6 weeks ago

Has patch: set

comment:6 by Mariusz Felisiak, 6 weeks ago

Needs documentation: set
Patch needs improvement: set

comment:7 by Lily Foote, 6 weeks ago

Needs documentation: unset
Patch needs improvement: unset

comment:8 by Sarah Boyce, 6 weeks ago

Patch needs improvement: set

comment:9 by Sarah Boyce, 6 weeks ago

Needs tests: set
Note: See TracTickets for help on using tickets.
Back to Top