Ticket #28121: 28121_1_10.patch

File 28121_1_10.patch, 1.6 KB (added by Thomas Achtemichuk, 7 years ago)

Test and patch for 1.10

  • django/utils/encoding.py

    diff --git a/django/utils/encoding.py b/django/utils/encoding.py
    index 66077e2108..bd5ec195db 100644
    a b from decimal import Decimal  
    88
    99from django.utils import six
    1010from django.utils.functional import Promise
     11from django.utils.safestring import SafeBytes
    1112from django.utils.six.moves.urllib.parse import quote, unquote
    1213
    1314if six.PY3:
    def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):  
    6869    if strings_only and is_protected_type(s):
    6970        return s
    7071    try:
    71         if not issubclass(type(s), six.string_types):
     72        if not issubclass(type(s), six.string_types + (SafeBytes,)):
    7273            if six.PY3:
    7374                if isinstance(s, bytes):
    7475                    s = six.text_type(s, encoding, errors)
  • tests/utils_tests/test_encoding.py

    diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py
    index 5ddb18d069..438a1b3d10 100644
    a b from django.utils.encoding import (  
    1111)
    1212from django.utils.functional import SimpleLazyObject
    1313from django.utils.http import urlquote_plus
     14from django.utils.safestring import SafeBytes, SafeText
    1415
    1516
    1617class TestEncodingUtils(unittest.TestCase):
    class TestEncodingUtils(unittest.TestCase):  
    4849        today = datetime.date.today()
    4950        self.assertEqual(force_bytes(today, strings_only=True), today)
    5051
     52    def test_force_text_safe_bytes(self):
     53        s = SafeBytes(b'')
     54        self.assertIsInstance(force_text(s), SafeText)
     55
    5156    def test_smart_text(self):
    5257        class Test:
    5358            if six.PY3:
Back to Top