diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 999ffae19a..1a2a162fd2 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'):
|
| 68 | 69 | if strings_only and is_protected_type(s): |
| 69 | 70 | return s |
| 70 | 71 | try: |
| 71 | | if not issubclass(type(s), six.string_types): |
| | 72 | if not issubclass(type(s), six.string_types + (SafeBytes,)): |
| 72 | 73 | if six.PY3: |
| 73 | 74 | if isinstance(s, bytes): |
| 74 | 75 | s = six.text_type(s, encoding, errors) |
diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py
index 688b46194d..633247afda 100644
|
a
|
b
|
from django.utils.encoding import (
|
| 11 | 11 | ) |
| 12 | 12 | from django.utils.functional import SimpleLazyObject |
| 13 | 13 | from django.utils.http import urlquote_plus |
| | 14 | from django.utils.safestring import SafeBytes, SafeText |
| 14 | 15 | |
| 15 | 16 | |
| 16 | 17 | class TestEncodingUtils(unittest.TestCase): |
| … |
… |
class TestEncodingUtils(unittest.TestCase):
|
| 48 | 49 | today = datetime.date.today() |
| 49 | 50 | self.assertEqual(force_bytes(today, strings_only=True), today) |
| 50 | 51 | |
| | 52 | def test_force_text_safe_bytes(self): |
| | 53 | s = SafeBytes(b'') |
| | 54 | self.assertIsInstance(force_text(s), SafeText) |
| | 55 | |
| 51 | 56 | def test_smart_text(self): |
| 52 | 57 | class Test: |
| 53 | 58 | if six.PY3: |