Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17111 -- Made the `redirect_to` generic view properly handle q…

…uery strings with percent symbols. Thanks, Chris Adams.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17034 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4d79083453e472d82633c5158ccbc5d6f6a6e247 1 parent 2e2689c
Julien Phalip authored October 26, 2011
10  django/views/generic/simple.py
@@ -49,12 +49,16 @@ def redirect_to(request, url, permanent=True, query_string=False, **kwargs):
49 49
 
50 50
     """
51 51
     args = request.META.get('QUERY_STRING', '')
52  
-    if args and query_string and url is not None:
53  
-        url = "%s?%s" % (url, args)
54 52
 
55 53
     if url is not None:
  54
+        if kwargs:
  55
+            url = url % kwargs
  56
+
  57
+        if args and query_string:
  58
+            url = "%s?%s" % (url, args)
  59
+
56 60
         klass = permanent and HttpResponsePermanentRedirect or HttpResponseRedirect
57  
-        return klass(url % kwargs)
  61
+        return klass(url)
58 62
     else:
59 63
         logger.warning('Gone: %s' % request.path,
60 64
                     extra={
1  tests/regressiontests/views/generic_urls.py
@@ -115,4 +115,5 @@
115 115
     (r'^simple/redirect_to_none/$', 'redirect_to', dict(url=None)),
116 116
     (r'^simple/redirect_to_arg/(?P<id>\d+)/$', 'redirect_to', dict(url='/simple/target_arg/%(id)s/')),
117 117
     (r'^simple/redirect_to_query/$', 'redirect_to', dict(url='/simple/target/', query_string=True)),
  118
+    (r'^simple/redirect_to_arg_and_query/(?P<id>\d+)/$', 'redirect_to', dict(url='/simple/target_arg/%(id)s/', query_string=True)),
118 119
 )
10  tests/regressiontests/views/tests/generic/simple.py
@@ -48,9 +48,17 @@ def test_redirect_to_allows_query_string_to_be_passed(self):
48 48
         self.assertEqual(response.status_code, 301)
49 49
         self.assertEqual('http://testserver/simple/target/?param1=foo&param2=bar', response['Location'])
50 50
 
  51
+        # Confirm that the contents of the query string are not subject to
  52
+        # string interpolation (Refs #17111):
  53
+        response = self.client.get('/simple/redirect_to_query/?param1=foo&param2=hist%C3%B3ria')
  54
+        self.assertEqual(response.status_code, 301)
  55
+        self.assertEqual('http://testserver/simple/target/?param1=foo&param2=hist%C3%B3ria', response['Location'])
  56
+        response = self.client.get('/simple/redirect_to_arg_and_query/99/?param1=foo&param2=hist%C3%B3ria')
  57
+        self.assertEqual(response.status_code, 301)
  58
+        self.assertEqual('http://testserver/simple/target_arg/99/?param1=foo&param2=hist%C3%B3ria', response['Location'])
  59
+
51 60
     def test_redirect_to_when_meta_contains_no_query_string(self):
52 61
         "regression for #16705"
53 62
         # we can't use self.client.get because it always sets QUERY_STRING
54 63
         response = self.client.request(PATH_INFO='/simple/redirect_to/')
55 64
         self.assertEqual(response.status_code, 301)
56  
-        

0 notes on commit 4d79083

Please sign in to comment.
Something went wrong with that request. Please try again.