Ticket #20108: 20108-2.diff

File 20108-2.diff, 1.4 KB (added by Claude Paroz, 7 years ago)

A variant patch (python 3 compatible)

  • django/utils/encoding.py

    diff --git a/django/utils/encoding.py b/django/utils/encoding.py
    index efc4ecc..adab0d0 100644
    a b def filepath_to_uri(path): 
    234234        return path
    235235    # I know about `os.sep` and `os.altsep` but I want to leave
    236236    # some flexibility for hardcoding separators.
    237     return quote(force_bytes(path.replace("\\", "/")), safe=b"/~!*()'")
     237    return quote(force_bytes(path).replace(b"\\", b"/"), safe=b"/~!*()'")
    238238
    239239def get_system_encoding():
    240240    """
  • tests/utils_tests/encoding.py

    diff --git a/tests/utils_tests/encoding.py b/tests/utils_tests/encoding.py
    index d191845..7aaba25 100644
    a b  
    22from __future__ import unicode_literals
    33
    44from django.utils import unittest
    5 from django.utils.encoding import force_bytes
     5from django.utils.encoding import force_bytes, filepath_to_uri
    66
    77
    88class TestEncodingUtils(unittest.TestCase):
    class TestEncodingUtils(unittest.TestCase): 
    1515        exc = ValueError(error_msg)
    1616        result = force_bytes(exc)
    1717        self.assertEqual(result, error_msg.encode('utf-8'))
     18
     19    def test_filepath_to_uri(self):
     20        self.assertEqual(filepath_to_uri('upload\\чубака.mp4'),
     21            'upload/%D1%87%D1%83%D0%B1%D0%B0%D0%BA%D0%B0.mp4')
     22        self.assertEqual(filepath_to_uri('upload\\чубака.mp4'.encode('utf-8')),
     23            'upload/%D1%87%D1%83%D0%B1%D0%B0%D0%BA%D0%B0.mp4')
Back to Top