Django

Code

Ticket #2078 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch] HttpResponseRedirect should percent-encode non-ASCII characters in Location header

Reported by: Andrey <aela@gorodok.net> Assigned to: adrian
Milestone: Component: Core framework
Version: Keywords:
Cc: aela@gorodok.net Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

urlescape.py (447 bytes) - added by Andrey <aela@gorodok.net> on 06/04/06 01:14:29.
A simple code for percent-encoding of strings
urlencode.diff (1.0 kB) - added by Andrey on 06/05/06 09:14:13.
Use urllib.quote for percent-encoding URLs in HttpResponseRedirect? and HttpResponsePermanentRedirect?

Change History

06/04/06 01:14:29 changed by Andrey <aela@gorodok.net>

  • attachment urlescape.py added.

A simple code for percent-encoding of strings

06/04/06 20:05:51 changed by adrian

  • summary changed from HttpResponseRedirect should percent-encode non-ASCII characters in Location header to [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?

06/05/06 09:10:58 changed by Andrey

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="!*'();:@&=+$,/?%#[]")

06/05/06 09:14:13 changed by Andrey

  • attachment urlencode.diff added.

Use urllib.quote for percent-encoding URLs in HttpResponseRedirect? and HttpResponsePermanentRedirect?

06/05/06 09:54:17 changed by anonymous

  • cc set to aela@gorodok.net.

06/08/06 02:08:51 changed by Alexander Petrov

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. :)

06/12/06 07:09:57 changed by Home

  • type deleted.

06/18/06 01:42:58 changed by anonymous

  • type set to defect.

06/19/06 23:06:16 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

(In [3166]) Fixed #2078 -- Improved HttpResponseRedirect? and HttpResponsePermanentRedirect? to percent-encode non-ASCII characters in the Location header. Thanks, Andrey


Add/Change #2078 ([patch] HttpResponseRedirect should percent-encode non-ASCII characters in Location header)




Change Properties
Action