Opened 4 years ago

Closed 4 years ago

Last modified 4 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 4 years ago.
fix with tests
20108-2.diff (1.4 KB) - added by Claude Paroz 4 years ago.
A variant patch (python 3 compatible)

Download all attachments as: .zip

Change History (5)

Changed 4 years ago by Ivan Virabyan

Attachment: filepath_to_uri_error.diff added

fix with tests

comment:1 Changed 4 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

Changed 4 years ago by Claude Paroz

Attachment: 20108-2.diff added

A variant patch (python 3 compatible)

comment:2 Changed 4 years ago by Claude Paroz <claude@…>

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 Changed 4 years ago by Claude Paroz <claude@…>

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