Code

Opened 16 months ago

Closed 16 months ago

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

Download all attachments as: .zip

Change History (5)

Changed 16 months ago by ivan_virabyan

fix with tests

comment:1 Changed 16 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 16 months ago by claudep

A variant patch (python 3 compatible)

comment:2 Changed 16 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

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 16 months 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.