diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 99c9da843a..efb2868563 100644
a
|
b
|
from decimal import Decimal
|
8 | 8 | |
9 | 9 | from django.utils import six |
10 | 10 | from django.utils.functional import Promise |
| 11 | from django.utils.safestring import SafeBytes |
11 | 12 | from django.utils.six.moves.urllib.parse import quote, unquote |
12 | 13 | |
13 | 14 | if six.PY3: |
… |
… |
def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
|
82 | 83 | if strings_only and is_protected_type(s): |
83 | 84 | return s |
84 | 85 | try: |
85 | | if not isinstance(s, six.string_types): |
| 86 | if not isinstance(s, six.string_types + (SafeBytes,)): |
86 | 87 | if six.PY3: |
87 | 88 | if isinstance(s, bytes): |
88 | 89 | s = six.text_type(s, encoding, errors) |
diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py
index e581003d9a..b6a9305f6f 100644
a
|
b
|
from django.utils.encoding import (
|
10 | 10 | uri_to_iri, |
11 | 11 | ) |
12 | 12 | from django.utils.http import urlquote_plus |
| 13 | from django.utils.safestring import SafeBytes, SafeText |
13 | 14 | |
14 | 15 | |
15 | 16 | class TestEncodingUtils(unittest.TestCase): |
… |
… |
class TestEncodingUtils(unittest.TestCase):
|
42 | 43 | today = datetime.date.today() |
43 | 44 | self.assertEqual(force_bytes(today, strings_only=True), today) |
44 | 45 | |
| 46 | def test_force_text_safe_bytes(self): |
| 47 | s = SafeBytes(b'') |
| 48 | self.assertIsInstance(force_text(s), SafeText) |
| 49 | |
45 | 50 | def test_escape_uri_path(self): |
46 | 51 | self.assertEqual( |
47 | 52 | escape_uri_path('/;some/=awful/?path/:with/@lots/&of/+awful/chars'), |