Fixed #2078 -- Improved HttpResponseRedirect and HttpResponsePermanentRedirect 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
This commit is contained in:
Adrian Holovaty 2006-06-20 04:06:16 +00:00
parent 6b730e1e92
commit 7aec348677
1 changed files with 5 additions and 3 deletions

View File

@ -1,8 +1,10 @@
from Cookie import SimpleCookie from Cookie import SimpleCookie
from pprint import pformat from pprint import pformat
from urllib import urlencode from urllib import urlencode, quote
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
try: try:
# The mod_python version is more efficient, so try importing it first. # The mod_python version is more efficient, so try importing it first.
from mod_python.util import parse_qsl from mod_python.util import parse_qsl
@ -242,13 +244,13 @@ class HttpResponse(object):
class HttpResponseRedirect(HttpResponse): class HttpResponseRedirect(HttpResponse):
def __init__(self, redirect_to): def __init__(self, redirect_to):
HttpResponse.__init__(self) HttpResponse.__init__(self)
self['Location'] = redirect_to self['Location'] = quote(redirect_to, safe=RESERVED_CHARS)
self.status_code = 302 self.status_code = 302
class HttpResponsePermanentRedirect(HttpResponse): class HttpResponsePermanentRedirect(HttpResponse):
def __init__(self, redirect_to): def __init__(self, redirect_to):
HttpResponse.__init__(self) HttpResponse.__init__(self)
self['Location'] = redirect_to self['Location'] = quote(redirect_to, safe=RESERVED_CHARS)
self.status_code = 301 self.status_code = 301
class HttpResponseNotModified(HttpResponse): class HttpResponseNotModified(HttpResponse):