Author: jezdez
Date: 2012-03-02 08:55:56 -0800 (Fri, 02 Mar 2012)
New Revision: 17625

Modified:
   django/trunk/django/views/generic/base.py
   django/trunk/tests/regressiontests/generic_views/base.py
Log:
Fixed #16842 -- Modified the RedirectView to correctly handle query strings 
with percent symbols. Thanks, accuser, [email protected] and Claude Paroz.

Modified: django/trunk/django/views/generic/base.py
===================================================================
--- django/trunk/django/views/generic/base.py   2012-03-02 16:45:06 UTC (rev 
17624)
+++ django/trunk/django/views/generic/base.py   2012-03-02 16:55:56 UTC (rev 
17625)
@@ -139,12 +139,11 @@
         are provided as kwargs to this method.
         """
         if self.url:
+            url = self.url % kwargs
             args = self.request.META.get('QUERY_STRING', '')
             if args and self.query_string:
-                url = "%s?%s" % (self.url, args)
-            else:
-                url = self.url
-            return url % kwargs
+                url = "%s?%s" % (url, args)
+            return url
         else:
             return None
 

Modified: django/trunk/tests/regressiontests/generic_views/base.py
===================================================================
--- django/trunk/tests/regressiontests/generic_views/base.py    2012-03-02 
16:45:06 UTC (rev 17624)
+++ django/trunk/tests/regressiontests/generic_views/base.py    2012-03-02 
16:55:56 UTC (rev 17625)
@@ -283,6 +283,13 @@
         self.assertEqual(response.status_code, 301)
         self.assertEqual(response['Location'], '/bar/?pork=spam')
 
+    def test_include_urlencoded_args(self):
+        "GET arguments can be URL-encoded when included in the redirected URL"
+        response = RedirectView.as_view(url='/bar/', query_string=True)(
+            self.rf.get('/foo/?unicode=%E2%9C%93'))
+        self.assertEqual(response.status_code, 301)
+        self.assertEqual(response['Location'], '/bar/?unicode=%E2%9C%93')
+
     def test_parameter_substitution(self):
         "Redirection URLs can be parameterized"
         response = 
RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), 
object_id=42)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to