mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #21574 -- Handle bytes consistently in utils.text.normalize_newlines.
All input is now coerced to text before being normalized. This changes nothing under Python 2 but it allows bytes to be passed to the function without a TypeError under Python3 (bytes are assumed to be utf-8 encoded text). Thanks to trac user vajrasky for the report.
This commit is contained in:
parent
b9c7234e2a
commit
2c837233f5
2 changed files with 10 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils import text
|
||||
from django.utils import six, text
|
||||
|
||||
|
||||
class TestUtilsText(SimpleTestCase):
|
||||
|
@ -114,6 +114,12 @@ class TestUtilsText(SimpleTestCase):
|
|||
self.assertEqual(text.normalize_newlines("abcdefghi"), "abcdefghi")
|
||||
self.assertEqual(text.normalize_newlines(""), "")
|
||||
|
||||
def test_normalize_newlines_bytes(self):
|
||||
"""normalize_newlines should be able to handle bytes too"""
|
||||
normalized = text.normalize_newlines(b"abc\ndef\rghi\r\n")
|
||||
self.assertEqual(normalized, "abc\ndef\nghi\n")
|
||||
self.assertIsInstance(normalized, six.text_type)
|
||||
|
||||
def test_slugify(self):
|
||||
items = (
|
||||
('Hello, World!', 'hello-world'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue