Ticket #2078: urlencode.diff

File urlencode.diff, 1.0 KB (added by Andrey, 9 years ago)

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

  • django/http/__init__.py

     
    11from Cookie import SimpleCookie
    22from pprint import pformat
    3 from urllib import urlencode
     3from urllib import urlencode, quote
    44from django.utils.datastructures import MultiValueDict
    55
     6RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
     7
    68try:
    79    # The mod_python version is more efficient, so try importing it first.
    810    from mod_python.util import parse_qsl
     
    241243class HttpResponseRedirect(HttpResponse):
    242244    def __init__(self, redirect_to):
    243245        HttpResponse.__init__(self)
    244         self['Location'] = redirect_to
     246        self['Location'] = quote(redirect_to, safe=RESERVED_CHARS)
    245247        self.status_code = 302
    246248
    247249class HttpResponsePermanentRedirect(HttpResponse):
    248250    def __init__(self, redirect_to):
    249251        HttpResponse.__init__(self)
    250         self['Location'] = redirect_to
     252        self['Location'] = quote(redirect_to, safe=RESERVED_CHARS)
    251253        self.status_code = 301
    252254
    253255class HttpResponseNotModified(HttpResponse):
Back to Top