From 7aec348677543de53552738e5dcbfd7cd496c58d Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 20 Jun 2006 04:06:16 +0000 Subject: [PATCH] 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 --- django/http/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/django/http/__init__.py b/django/http/__init__.py index efc1286f6d..8fb4b293fc 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -1,8 +1,10 @@ from Cookie import SimpleCookie from pprint import pformat -from urllib import urlencode +from urllib import urlencode, quote from django.utils.datastructures import MultiValueDict +RESERVED_CHARS="!*'();:@&=+$,/?%#[]" + try: # The mod_python version is more efficient, so try importing it first. from mod_python.util import parse_qsl @@ -242,13 +244,13 @@ class HttpResponse(object): class HttpResponseRedirect(HttpResponse): def __init__(self, redirect_to): HttpResponse.__init__(self) - self['Location'] = redirect_to + self['Location'] = quote(redirect_to, safe=RESERVED_CHARS) self.status_code = 302 class HttpResponsePermanentRedirect(HttpResponse): def __init__(self, redirect_to): HttpResponse.__init__(self) - self['Location'] = redirect_to + self['Location'] = quote(redirect_to, safe=RESERVED_CHARS) self.status_code = 301 class HttpResponseNotModified(HttpResponse):