Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#20108 closed Bug (fixed)

filepath_to_uri raises UnicodeDecodeError on utf8 input

Reported by: Ivan Virabyan Owned by: nobody
Component: Utilities Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The docs say "The path is assumed to be either UTF-8 or unicode." in https://docs.djangoproject.com/en/1.5/ref/utils/#django.utils.encoding.filepath_to_uri:

>>> filepath_to_uri('тест')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/kanobu/env/lib/python2.7/site-packages/django/utils/encoding.py", line 235, in filepath_to_uri
    return quote(force_bytes(path.replace("\\", "/")), safe=b"/~!*()'")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

Since the module django.utils.encoding uses unicode literals, code path.replace("\", "/") fails, because it tries to decode path

Attachments (2)

filepath_to_uri_error.diff (1.5 KB ) - added by Ivan Virabyan 12 years ago.
fix with tests
20108-2.diff (1.4 KB ) - added by Claude Paroz 12 years ago.
A variant patch (python 3 compatible)

Download all attachments as: .zip

Change History (5)

by Ivan Virabyan, 12 years ago

Attachment: filepath_to_uri_error.diff added

fix with tests

comment:1 by Claude Paroz, 12 years ago

Triage Stage: UnreviewedAccepted

by Claude Paroz, 12 years ago

Attachment: 20108-2.diff added

A variant patch (python 3 compatible)

comment:2 by Claude Paroz <claude@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 164528acc8752f33a3af4c1255b24702a4c81240:

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.

comment:3 by Claude Paroz <claude@…>, 12 years ago

In deec020bf5927abbdd667912f80794c32c03e609:

[1.5.x] 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.
Backport of 164528acc8 from master.

Note: See TracTickets for help on using tickets.
Back to Top