Refs #27795 -- Removed force_bytes() usage in utils/_os.py.
This commit is contained in:
parent
9a0e0d966a
commit
bb81c22d90
|
@ -3,7 +3,6 @@ import tempfile
|
||||||
from os.path import abspath, dirname, join, normcase, sep
|
from os.path import abspath, dirname, join, normcase, sep
|
||||||
|
|
||||||
from django.core.exceptions import SuspiciousFileOperation
|
from django.core.exceptions import SuspiciousFileOperation
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
# For backwards-compatibility in Django 2.0
|
# For backwards-compatibility in Django 2.0
|
||||||
abspathu = abspath
|
abspathu = abspath
|
||||||
|
@ -30,8 +29,6 @@ def safe_join(base, *paths):
|
||||||
Raise ValueError if the final path isn't located inside of the base path
|
Raise ValueError if the final path isn't located inside of the base path
|
||||||
component.
|
component.
|
||||||
"""
|
"""
|
||||||
base = force_text(base)
|
|
||||||
paths = [force_text(p) for p in paths]
|
|
||||||
final_path = abspath(join(base, *paths))
|
final_path = abspath(join(base, *paths))
|
||||||
base_path = abspath(base)
|
base_path = abspath(base)
|
||||||
# Ensure final_path starts with base_path (using normcase to ensure we
|
# Ensure final_path starts with base_path (using normcase to ensure we
|
||||||
|
|
|
@ -291,6 +291,8 @@ Miscellaneous
|
||||||
is now the real ellipsis character (``…``) instead of 3 dots. You may have to
|
is now the real ellipsis character (``…``) instead of 3 dots. You may have to
|
||||||
adapt some test output comparisons.
|
adapt some test output comparisons.
|
||||||
|
|
||||||
|
* Support for bytestring paths in the template filesystem loader is removed.
|
||||||
|
|
||||||
.. _deprecated-features-2.2:
|
.. _deprecated-features-2.2:
|
||||||
|
|
||||||
Features deprecated in 2.2
|
Features deprecated in 2.2
|
||||||
|
|
|
@ -156,24 +156,17 @@ class FileSystemLoaderTests(SimpleTestCase):
|
||||||
|
|
||||||
def test_unicode_template_name(self):
|
def test_unicode_template_name(self):
|
||||||
with self.source_checker(['/dir1', '/dir2']) as check_sources:
|
with self.source_checker(['/dir1', '/dir2']) as check_sources:
|
||||||
# UTF-8 bytestrings are permitted.
|
|
||||||
check_sources(b'\xc3\x85ngstr\xc3\xb6m', ['/dir1/Ångström', '/dir2/Ångström'])
|
|
||||||
# Strings are permitted.
|
|
||||||
check_sources('Ångström', ['/dir1/Ångström', '/dir2/Ångström'])
|
check_sources('Ångström', ['/dir1/Ångström', '/dir2/Ångström'])
|
||||||
|
|
||||||
def test_utf8_bytestring(self):
|
def test_bytestring(self):
|
||||||
"""
|
loader = self.engine.template_loaders[0]
|
||||||
Invalid UTF-8 encoding in bytestrings should raise a useful error
|
msg = "Can't mix strings and bytes in path components"
|
||||||
"""
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
engine = self.engine
|
list(loader.get_template_sources(b'\xc3\x85ngstr\xc3\xb6m'))
|
||||||
loader = engine.template_loaders[0]
|
|
||||||
with self.assertRaises(UnicodeDecodeError):
|
|
||||||
list(loader.get_template_sources(b'\xc3\xc3'))
|
|
||||||
|
|
||||||
def test_unicode_dir_name(self):
|
def test_unicode_dir_name(self):
|
||||||
with self.source_checker([b'/Stra\xc3\x9fe']) as check_sources:
|
with self.source_checker(['/Straße']) as check_sources:
|
||||||
check_sources('Ångström', ['/Straße/Ångström'])
|
check_sources('Ångström', ['/Straße/Ångström'])
|
||||||
check_sources(b'\xc3\x85ngstr\xc3\xb6m', ['/Straße/Ångström'])
|
|
||||||
|
|
||||||
@unittest.skipUnless(
|
@unittest.skipUnless(
|
||||||
os.path.normcase('/TEST') == os.path.normpath('/test'),
|
os.path.normcase('/TEST') == os.path.normpath('/test'),
|
||||||
|
|
Loading…
Reference in New Issue