Ticket #14288: fix_windows_lineendings_breaking_linebreaksbr.patch

File fix_windows_lineendings_breaking_linebreaksbr.patch, 1.2 KB (added by Michiel, 14 years ago)

Patch

  • django/template/defaultfilters.py

     
    426426    Converts all newlines in a piece of plain text to HTML line breaks
    427427    (``<br />``).
    428428    """
     429    value = re.sub(r'\r\n|\r|\n', '\n', force_unicode(value)) # normalize newlines
    429430    if autoescape and not isinstance(value, SafeData):
    430431        from django.utils.html import escape
    431432        value = escape(value)
  • tests/regressiontests/defaultfilters/tests.py

     
    266266>>> linebreaks(u'line 1\nline 2')
    267267u'<p>line 1<br />line 2</p>'
    268268
     269>>> linebreaks(u'line 1\r\nline 2')
     270u'<p>line 1<br />line 2</p>'
     271
     272>>> linebreaksbr(u'line 1\nline 2')
     273u'line 1<br />line 2'
     274
     275>>> linebreaksbr(u'line 1\r\nline 2')
     276u'line 1<br />line 2'
     277
    269278>>> removetags(u'some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags', 'script img')
    270279u'some <b>html</b> with alert("You smell") disallowed  tags'
    271280
Back to Top