Ticket #14809: 14809.5.diff

File 14809.5.diff, 6.6 KB (added by Jannis Leidel, 14 years ago)

Removed forced use of urlquote

  • django/contrib/auth/tests/views.py

    diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py
    index 88867d5..014c819 100644
    a b class LoginURLSettings(AuthViewsTestCase):  
    265265        querystring = QueryDict('', mutable=True)
    266266        querystring['next'] = '/login_required/'
    267267        self.assertEqual(login_required_url,
    268              'http://testserver%s?%s' % (login_url, querystring.urlencode()))
     268             'http://testserver%s?%s' % (login_url, querystring.urlencode('/')))
    269269
    270270    def test_remote_login_url(self):
    271271        login_url = 'http://remote.example.com/login'
    class LoginURLSettings(AuthViewsTestCase):  
    273273        querystring = QueryDict('', mutable=True)
    274274        querystring['next'] = 'http://testserver/login_required/'
    275275        self.assertEqual(login_required_url,
    276                          '%s?%s' % (login_url, querystring.urlencode()))
     276                         '%s?%s' % (login_url, querystring.urlencode('/')))
    277277
    278278    def test_https_login_url(self):
    279279        login_url = 'https:///login/'
    class LoginURLSettings(AuthViewsTestCase):  
    281281        querystring = QueryDict('', mutable=True)
    282282        querystring['next'] = 'http://testserver/login_required/'
    283283        self.assertEqual(login_required_url,
    284                          '%s?%s' % (login_url, querystring.urlencode()))
     284                         '%s?%s' % (login_url, querystring.urlencode('/')))
    285285
    286286    def test_login_url_with_querystring(self):
    287287        login_url = '/login/?pretty=1'
    class LoginURLSettings(AuthViewsTestCase):  
    289289        querystring = QueryDict('pretty=1', mutable=True)
    290290        querystring['next'] = '/login_required/'
    291291        self.assertEqual(login_required_url, 'http://testserver/login/?%s' %
    292                          querystring.urlencode())
     292                         querystring.urlencode('/'))
    293293
    294294    def test_remote_login_url_with_next_querystring(self):
    295295        login_url = 'http://remote.example.com/login/'
    class LoginURLSettings(AuthViewsTestCase):  
    298298        querystring = QueryDict('', mutable=True)
    299299        querystring['next'] = 'http://testserver/login_required/'
    300300        self.assertEqual(login_required_url, '%s?%s' % (login_url,
    301                                                     querystring.urlencode()))
    302        
     301                                                    querystring.urlencode('/')))
     302
     303
    303304class LogoutTest(AuthViewsTestCase):
    304305    urls = 'django.contrib.auth.tests.urls'
    305306
  • django/contrib/auth/views.py

    diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
    index d1f0e06..06bf8f4 100644
    a b def redirect_to_login(next, login_url=None,  
    108108    if redirect_field_name:
    109109        querystring = QueryDict(login_url_parts[4], mutable=True)
    110110        querystring[redirect_field_name] = next
    111         login_url_parts[4] = querystring.urlencode()
     111        login_url_parts[4] = querystring.urlencode(safe='/')
    112112
    113113    return HttpResponseRedirect(urlparse.urlunparse(login_url_parts))
    114114
  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index 42027f0..6526c63 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, e.g.::
     371
     372            >>> q = QueryDict('', mutable=True)
     373            >>> q['next'] = '/a&b/'
     374            >>> q.urlencode()
     375            'next=%2Fa%26b%2F'
     376            >>> q.urlencode(safe='/')
     377            'next=/a%26b/'
     378
     379        """
    367380        output = []
     381        if safe:
     382            encode = lambda k, v: u'%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            output.extend([encode(k, smart_str(v, self.encoding)) for v in list_])
    371388        return '&'.join(output)
    372389
    373390class CompatCookie(SimpleCookie):
  • docs/ref/request-response.txt

    diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
    index cc89229..036cb8d 100644
    a b In addition, ``QueryDict`` has the following methods:  
    430430    Like :meth:`items()`, except it includes all values, as a list, for each
    431431    member of the dictionary. For example::
    432432
    433          >>> q = QueryDict('a=1&a=2&a=3')
    434          >>> q.lists()
    435          [(u'a', [u'1', u'2', u'3'])]
     433        >>> q = QueryDict('a=1&a=2&a=3')
     434        >>> q.lists()
     435        [(u'a', [u'1', u'2', u'3'])]
    436436
    437 .. method:: QueryDict.urlencode()
     437.. method:: QueryDict.urlencode([safe])
    438438
    439     Returns a string of the data in query-string format.
    440     Example: ``"a=2&b=3&b=5"``.
     439    Returns a string of the data in query-string format. Example::
     440
     441        >>> q = QueryDict('a=2&b=3&b=5')
     442        >>> q.urlencode()
     443        'a=2&b=3&b=5'
     444
     445    .. versionadded:: 1.3
     446
     447    Optionally, urlencode can be passed characters which
     448    do not require encoding. For example::
     449
     450        >>> q = QueryDict('/a&b/')
     451        >>> q.urlencode(safe='/')
     452        'next=/a%26b/'
    441453
    442454HttpResponse objects
    443455====================
  • tests/regressiontests/httpwrappers/tests.py

    diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
    index 6d45252..65b06a1 100644
    a b class QueryDictTests(unittest.TestCase):  
    7171
    7272        self.assertEqual(q.urlencode(), 'foo=bar')
    7373
     74    def test_urlencode(self):
     75        q = QueryDict('', mutable=True)
     76        q['next'] = '/a&b/'
     77        self.assertEqual(q.urlencode(), 'next=%2Fa%26b%2F')
     78        self.assertEqual(q.urlencode(safe='/'), 'next=/a%26b/')
     79        q = QueryDict('', mutable=True)
     80        q['next'] = u'/t\xebst&key/'
     81        self.assertEqual(q.urlencode(), 'next=%2Ft%C3%ABst%26key%2F')
     82        self.assertEqual(q.urlencode(safe='/'), 'next=/t%C3%ABst%26key/')
     83
    7484    def test_mutable_copy(self):
    7585        """A copy of a QueryDict is mutable."""
    7686        q = QueryDict('').copy()
Back to Top