mirror of https://github.com/django/django.git
Fixed #20108 -- Fixed filepath_to_uri decoding error
This was a regression due to unicode_literals usage. Thanks Ivan Virabyan for the report and the initial patch.
This commit is contained in:
parent
829dc3c5a6
commit
164528acc8
|
@ -234,7 +234,7 @@ def filepath_to_uri(path):
|
||||||
return path
|
return path
|
||||||
# I know about `os.sep` and `os.altsep` but I want to leave
|
# I know about `os.sep` and `os.altsep` but I want to leave
|
||||||
# some flexibility for hardcoding separators.
|
# some flexibility for hardcoding separators.
|
||||||
return quote(force_bytes(path.replace("\\", "/")), safe=b"/~!*()'")
|
return quote(force_bytes(path).replace(b"\\", b"/"), safe=b"/~!*()'")
|
||||||
|
|
||||||
def get_system_encoding():
|
def get_system_encoding():
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes, filepath_to_uri
|
||||||
|
|
||||||
|
|
||||||
class TestEncodingUtils(unittest.TestCase):
|
class TestEncodingUtils(unittest.TestCase):
|
||||||
|
@ -15,3 +15,9 @@ class TestEncodingUtils(unittest.TestCase):
|
||||||
exc = ValueError(error_msg)
|
exc = ValueError(error_msg)
|
||||||
result = force_bytes(exc)
|
result = force_bytes(exc)
|
||||||
self.assertEqual(result, error_msg.encode('utf-8'))
|
self.assertEqual(result, error_msg.encode('utf-8'))
|
||||||
|
|
||||||
|
def test_filepath_to_uri(self):
|
||||||
|
self.assertEqual(filepath_to_uri('upload\\чубака.mp4'),
|
||||||
|
'upload/%D1%87%D1%83%D0%B1%D0%B0%D0%BA%D0%B0.mp4')
|
||||||
|
self.assertEqual(filepath_to_uri('upload\\чубака.mp4'.encode('utf-8')),
|
||||||
|
'upload/%D1%87%D1%83%D0%B1%D0%B0%D0%BA%D0%B0.mp4')
|
||||||
|
|
Loading…
Reference in New Issue