Opened 18 years ago
Closed 15 years ago
#2078 closed defect (fixed)
[patch] HttpResponseRedirect should percent-encode non-ASCII characters in Location header
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Core (Other) | Version: | |
Severity: | normal | Keywords: | |
Cc: | aela@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
RFC 3986 does not allow non-ASCII characters in URIs. Instead they should be converted to bytes according to UTF-8 and then replaced by %XX sequences, where XX is the hexadecimal value of the byte.
Attachments (2)
Change History (11)
by , 18 years ago
Attachment: | urlescape.py added |
---|
comment:1 by , 18 years ago
Summary: | HttpResponseRedirect should percent-encode non-ASCII characters in Location header → [patch] HttpResponseRedirect should percent-encode non-ASCII characters in Location header |
---|
Can we not use one of the utility functions in urllib
or urllib2
for this?
comment:2 by , 18 years ago
Yes, seems like urllib.quote
is almost what we need. We just have to tell it to leave HTTP reserved characters unquoted, like this: urllib.quote(url, safe="!*'();:@&=+$,/?%#[]")
by , 18 years ago
Attachment: | urlencode.diff added |
---|
Use urllib.quote for percent-encoding URLs in HttpResponseRedirect and HttpResponsePermanentRedirect
comment:3 by , 18 years ago
Cc: | added |
---|
comment:4 by , 18 years ago
I am currentry writing a Django-based mini-wiki, and of course I'd want to have non-latin character in article titles (I am a native Russian speaker). Unfortunately, Django still chokes on cyrilic characters in URLs. For example, if an URL with cyrillic character and wihout trailing slash is entered in browser (say, http://some.host/wiki/Проверка), it does not get redirected correctly (you get some cruft like http://some.host/wiki/ÐÑовеÑка/ instead of http://some.host/wiki/Проверка/).
This patch above fixes this issue, so it would be really nice to have it merged. :)
comment:5 by , 18 years ago
Type: | defect |
---|
comment:6 by , 18 years ago
Type: | → defect |
---|
comment:7 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:8 by , 15 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Recently I came across http://www.djangosnippets.org/snippets/1048/ and I found
params = {'v':'1.0', 'q': text.encode('utf-8')}
to be the encoded format for urlopening translation apis with non-ASCII characters,
when I didn't succeed in sending a escaped version used here to call translate api from django.
comment:9 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
The original bug was fixed three years ago. Please ask on django-users and open a new ticket with detailed information about your problem if you are sure it is a django bug.
A simple code for percent-encoding of strings