diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index 60fa59e..07fcebc 100644
a
|
b
|
from django.utils.encoding import force_unicode, iri_to_uri
|
12 | 12 | from django.utils.html import conditional_escape |
13 | 13 | from django.utils.safestring import mark_safe, SafeData |
14 | 14 | from django.utils.translation import ugettext, ungettext |
| 15 | from django.utils.text import normalize_newlines |
15 | 16 | |
16 | 17 | register = Library() |
17 | 18 | |
… |
… |
def linebreaksbr(value, autoescape=None):
|
414 | 415 | Converts all newlines in a piece of plain text to HTML line breaks |
415 | 416 | (``<br />``). |
416 | 417 | """ |
417 | | if autoescape and not isinstance(value, SafeData): |
| 418 | autoescape = autoescape and not isinstance(value, SafeData) |
| 419 | value = normalize_newlines(value) |
| 420 | if autoescape: |
418 | 421 | from django.utils.html import escape |
419 | 422 | value = escape(value) |
420 | 423 | return mark_safe(value.replace('\n', '<br />')) |
diff --git a/django/utils/html.py b/django/utils/html.py
index 7fda015..2687eb5 100644
a
|
b
|
from django.utils.safestring import SafeData, mark_safe
|
7 | 7 | from django.utils.encoding import force_unicode |
8 | 8 | from django.utils.functional import allow_lazy |
9 | 9 | from django.utils.http import urlquote |
| 10 | from django.utils.text import normalize_newlines |
10 | 11 | |
11 | 12 | # Configuration for urlize() function. |
12 | 13 | LEADING_PUNCTUATION = ['(', '<', '<'] |
… |
… |
def conditional_escape(html):
|
70 | 71 | |
71 | 72 | def linebreaks(value, autoescape=False): |
72 | 73 | """Converts newlines into <p> and <br />s.""" |
73 | | value = re.sub(r'\r\n|\r|\n', '\n', force_unicode(value)) # normalize newlines |
| 74 | value = normalize_newlines(value) |
74 | 75 | paras = re.split('\n{2,}', value) |
75 | 76 | if autoescape: |
76 | 77 | paras = [u'<p>%s</p>' % escape(p).replace('\n', '<br />') for p in paras] |
diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
index 77bd2ba..b471205 100644
a
|
b
|
class DefaultFiltersTests(TestCase):
|
266 | 266 | self.assertEqual(linebreaks(u'line 1'), u'<p>line 1</p>') |
267 | 267 | self.assertEqual(linebreaks(u'line 1\nline 2'), |
268 | 268 | u'<p>line 1<br />line 2</p>') |
| 269 | self.assertEqual(linebreaks(u'line 1\rline 2'), |
| 270 | u'<p>line 1<br />line 2</p>') |
| 271 | self.assertEqual(linebreaks(u'line 1\r\nline 2'), |
| 272 | u'<p>line 1<br />line 2</p>') |
| 273 | |
| 274 | def test_linebreaksbr(self): |
| 275 | self.assertEqual(linebreaksbr(u'line 1\nline 2'), |
| 276 | u'line 1<br />line 2') |
| 277 | self.assertEqual(linebreaksbr(u'line 1\rline 2'), |
| 278 | u'line 1<br />line 2') |
| 279 | self.assertEqual(linebreaksbr(u'line 1\r\nline 2'), |
| 280 | u'line 1<br />line 2') |
269 | 281 | |
270 | 282 | def test_removetags(self): |
271 | 283 | self.assertEqual(removetags(u'some <b>html</b> with <script>alert'\ |