[Django] #29372: linebreaksbr and linebreaks can not work in template filters

26 views
Skip to first unread message

Django

unread,
Apr 29, 2018, 12:11:41 PM4/29/18
to django-...@googlegroups.com
#29372: linebreaksbr and linebreaks can not work in template filters
-------------------------------------+-------------------------------------
Reporter: 何翔宇 | Owner: nobody
(Sean Ho) |
Type: Bug | Status: new
Component: Template | Version: 2.0
system | Keywords: linebreaksbr
Severity: Normal | linebreaks template-filters
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
In template, linebreaksbr and linebreaks can convert newlines in a piece
of plain text to HTML line breaks ( <br>).

They all use the same way which is "replace('\n', '<br>')", the correct
way is “"replace(r'\n', '<br>')”.


{{{
@register.filter(is_safe=True, needs_autoescape=True)
@stringfilter
def linebreaksbr(value, autoescape=True):
"""
Convert all newlines in a piece of plain text to HTML line breaks
(``<br>``).
"""
autoescape = autoescape and not isinstance(value, SafeData)
value = normalize_newlines(value)
if autoescape:
value = escape(value)
return mark_safe(value.replace('\n', '<br>'))
}}}


{{{
@keep_lazy_text
def linebreaks(value, autoescape=False):
"""Convert newlines into <p> and <br>s."""
value = normalize_newlines(value)
paras = re.split('\n{2,}', str(value))
if autoescape:
paras = ['<p>%s</p>' % escape(p).replace('\n', '<br>') for p in
paras]
else:
paras = ['<p>%s</p>' % p.replace('\n', '<br>') for p in paras]
return '\n\n'.join(paras)
}}}


Attachments is error result in html.

--
Ticket URL: <https://code.djangoproject.com/ticket/29372>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 29, 2018, 12:13:27 PM4/29/18
to django-...@googlegroups.com
#29372: linebreaksbr and linebreaks can not work in template filters
-------------------------------------+-------------------------------------
Reporter: 何翔宇(Sean Ho) | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 2.0
Severity: Normal | Resolution:
Keywords: linebreaksbr | Triage Stage:
linebreaks template-filters | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by 何翔宇(Sean Ho)):

* Attachment "inhtml.png" added.

Django

unread,
Apr 29, 2018, 12:14:57 PM4/29/18
to django-...@googlegroups.com
#29372: linebreaksbr and linebreaks can not work in template filters
-------------------------------------+-------------------------------------
Reporter: 何翔宇(Sean Ho) | Owner: 何翔宇
| (Sean Ho)
Type: Bug | Status: assigned

Component: Template system | Version: 2.0
Severity: Normal | Resolution:
Keywords: linebreaksbr | Triage Stage:
linebreaks template-filters | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by 何翔宇(Sean Ho)):

* status: new => assigned
* owner: nobody => 何翔宇(Sean Ho)


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

Django

unread,
Apr 29, 2018, 12:35:45 PM4/29/18
to django-...@googlegroups.com
#29372: linebreaksbr and linebreaks can not work in template filters
-------------------------------------+-------------------------------------
Reporter: 何翔宇(Sean Ho) | Owner: 何翔宇
| (Sean Ho)

Type: Bug | Status: assigned
Component: Template system | Version: 2.0
Severity: Normal | Resolution:
Keywords: linebreaksbr | Triage Stage:
linebreaks template-filters | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0

-------------------------------------+-------------------------------------
Changes (by 何翔宇(Sean Ho)):

* easy: 0 => 1


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

Django

unread,
Apr 29, 2018, 1:52:47 PM4/29/18
to django-...@googlegroups.com
#29372: linebreaksbr and linebreaks can not work in template filters
-------------------------------------+-------------------------------------
Reporter: 何翔宇(Sean Ho) | Owner: 何翔宇
| (Sean Ho)
Type: Bug | Status: closed

Component: Template system | Version: 2.0
Severity: Normal | Resolution: needsinfo

Keywords: linebreaksbr | Triage Stage:
linebreaks template-filters | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* status: assigned => closed
* resolution: => needsinfo


Comment:

Like I said on the PR, presenting a failing test case is the key to
convince us Django is at fault. Reopen the ticket as soon as you have it.

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

Reply all
Reply to author
Forward
0 new messages