Ticket #14809: 14809.2.diff

File 14809.2.diff, 2.1 KB (added by Chris Beaven, 14 years ago)
  • django/contrib/auth/views.py

    diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
    index 42ad68d..0325643 100644
    a b def redirect_to_login(next, login_url=None,  
    9999    if redirect_field_name:
    100100        querystring = QueryDict(login_url_parts[4], mutable=True)
    101101        querystring[redirect_field_name] = next
    102         login_url_parts[4] = querystring.urlencode()
     102        login_url_parts[4] = querystring.urlencode(safe='/')
    103103
    104104    return HttpResponseRedirect(urlparse.urlunparse(login_url_parts))
    105105
  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index 42027f0..0dde23e 100644
    a b import os  
    33import re
    44import time
    55from pprint import pformat
    6 from urllib import urlencode
     6from urllib import urlencode, quote
    77from urlparse import urljoin
    88try:
    99    from cStringIO import StringIO
    class QueryDict(MultiValueDict):  
    363363        """Returns a mutable copy of this object."""
    364364        return self.__deepcopy__({})
    365365
    366     def urlencode(self):
     366    def urlencode(self, safe=None):
     367        """
     368        Returns an encoded string of all query string arguments.
     369
     370        :arg safe: Used to specify characters which do not require quoting, for
     371            example::
     372
     373                >>> q = QueryDict()
     374                >>> q['next'] = '/a&b/'
     375                >>> q.urlencode()
     376                'next=%2Fa%26b%2F'
     377                >>> q.urlencode(safe='/')
     378                'next=/a%26b/'
     379        """
    367380        output = []
     381        if safe:
     382            encode = lambda k, v: '%s=%s' % ((quote(k, safe), quote(v, safe)))
     383        else:
     384            encode = lambda k, v: urlencode({k: v})
    368385        for k, list_ in self.lists():
    369386            k = smart_str(k, self.encoding)
    370             output.extend([urlencode({k: smart_str(v, self.encoding)}) for v in list_])
     387            for value in list_:
     388                output.append(encode(k, smart_str(value, self.encoding)))
    371389        return '&'.join(output)
    372390
    373391class CompatCookie(SimpleCookie):
Back to Top