Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2078 -- Improved HttpResponseRedirect and HttpResponsePermanen…

…tRedirect to percent-encode non-ASCII characters in the Location header. Thanks, Andrey

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3166 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7aec348677543de53552738e5dcbfd7cd496c58d 1 parent 6b730e1
Adrian Holovaty authored June 20, 2006

Showing 1 changed file with 5 additions and 3 deletions. Show diff stats Hide diff stats

  1. 8  django/http/__init__.py
8  django/http/__init__.py
... ...
@@ -1,8 +1,10 @@
1 1
 from Cookie import SimpleCookie
2 2
 from pprint import pformat
3  
-from urllib import urlencode
  3
+from urllib import urlencode, quote
4 4
 from django.utils.datastructures import MultiValueDict
5 5
 
  6
+RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
  7
+
6 8
 try:
7 9
     # The mod_python version is more efficient, so try importing it first.
8 10
     from mod_python.util import parse_qsl
@@ -242,13 +244,13 @@ def tell(self):
242 244
 class HttpResponseRedirect(HttpResponse):
243 245
     def __init__(self, redirect_to):
244 246
         HttpResponse.__init__(self)
245  
-        self['Location'] = redirect_to
  247
+        self['Location'] = quote(redirect_to, safe=RESERVED_CHARS)
246 248
         self.status_code = 302
247 249
 
248 250
 class HttpResponsePermanentRedirect(HttpResponse):
249 251
     def __init__(self, redirect_to):
250 252
         HttpResponse.__init__(self)
251  
-        self['Location'] = redirect_to
  253
+        self['Location'] = quote(redirect_to, safe=RESERVED_CHARS)
252 254
         self.status_code = 301
253 255
 
254 256
 class HttpResponseNotModified(HttpResponse):

0 notes on commit 7aec348

Please sign in to comment.
Something went wrong with that request. Please try again.