Ticket #20108: filepath_to_uri_error.diff

File filepath_to_uri_error.diff, 1.5 KB (added by Ivan Virabyan, 12 years ago)

fix with tests

  • django/utils/encoding.py

    diff --git a/django/utils/encoding.py b/django/utils/encoding.py
    index efc4ecc..b71ac27 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(smart_text(path).replace("\\", "/")), safe=b"/~!*()'")
    238238
    239239def get_system_encoding():
    240240    """
  • tests/text/tests.py

    diff --git a/tests/text/tests.py b/tests/text/tests.py
    index e61c14d..c85a5da 100644
    a b  
    22from __future__ import unicode_literals
    33
    44from django.test import TestCase
    5 from django.utils.encoding import iri_to_uri
     5from django.utils.encoding import iri_to_uri, filepath_to_uri
    66from django.utils.http import (cookie_date, http_date,
    77    urlquote, urlquote_plus, urlunquote, urlunquote_plus)
    88from django.utils.text import get_text_list, smart_split
    class TextTests(TestCase):  
    103103    def test_iri_to_uri_idempotent(self):
    104104        self.assertEqual(iri_to_uri(iri_to_uri('red%09ros\xe9#red')),
    105105            'red%09ros%C3%A9#red')
     106
     107    def test_filepath_to_uri(self):
     108        self.assertEqual(filepath_to_uri('upload\\чубака.mp4'),
     109            'upload/%D1%87%D1%83%D0%B1%D0%B0%D0%BA%D0%B0.mp4')
     110        self.assertEqual(filepath_to_uri(b'upload\\чубака.mp4'),
     111            b'upload/%D1%87%D1%83%D0%B1%D0%B0%D0%BA%D0%B0.mp4')
Back to Top