Ticket #28121: 28121_1_8.patch

File 28121_1_8.patch, 1.7 KB (added by Thomas Achtemichuk, 8 years ago)

Test and patch for 1.8

  • django/utils/encoding.py

    diff --git a/django/utils/encoding.py b/django/utils/encoding.py
    index 99c9da843a..efb2868563 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'):  
    8283    if strings_only and is_protected_type(s):
    8384        return s
    8485    try:
    85         if not isinstance(s, six.string_types):
     86        if not isinstance(s, six.string_types + (SafeBytes,)):
    8687            if six.PY3:
    8788                if isinstance(s, bytes):
    8889                    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 e581003d9a..b6a9305f6f 100644
    a b from django.utils.encoding import (  
    1010    uri_to_iri,
    1111)
    1212from django.utils.http import urlquote_plus
     13from django.utils.safestring import SafeBytes, SafeText
    1314
    1415
    1516class TestEncodingUtils(unittest.TestCase):
    class TestEncodingUtils(unittest.TestCase):  
    4243        today = datetime.date.today()
    4344        self.assertEqual(force_bytes(today, strings_only=True), today)
    4445
     46    def test_force_text_safe_bytes(self):
     47        s = SafeBytes(b'')
     48        self.assertIsInstance(force_text(s), SafeText)
     49
    4550    def test_escape_uri_path(self):
    4651        self.assertEqual(
    4752            escape_uri_path('/;some/=awful/?path/:with/@lots/&of/+awful/chars'),
Back to Top