Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10585: comment redirects built from the `next` parameter now w…

…ork correctly when `next` already contains a query string.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10424 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6319470f88d464204c0f62622cc3f8ff081bce0f 1 parent eef2c5f
Jacob Kaplan-Moss authored April 07, 2009
3  django/contrib/comments/views/utils.py
@@ -25,7 +25,8 @@ def next_redirect(data, default, default_view, **get_kwargs):
25 25
     if next is None:
26 26
         next = urlresolvers.reverse(default_view)
27 27
     if get_kwargs:
28  
-        next += "?" + urllib.urlencode(get_kwargs)
  28
+        joiner = ('?' in next) and '&' or '?'
  29
+        next += joiner + urllib.urlencode(get_kwargs)
29 30
     return HttpResponseRedirect(next)
30 31
 
31 32
 def confirmation_view(template, doc="Display a confirmation view."):
13  tests/regressiontests/comment_tests/tests/comment_view_tests.py
@@ -207,3 +207,16 @@ def testCommentDoneView(self):
207 207
         self.assertTemplateUsed(response, "comments/posted.html")
208 208
         self.assertEqual(response.context[0]["comment"], Comment.objects.get(pk=pk))
209 209
 
  210
+    def testCommentNextWithQueryString(self):
  211
+        """
  212
+        The `next` key needs to handle already having a query string (#10585)
  213
+        """
  214
+        a = Article.objects.get(pk=1)
  215
+        data = self.getValidData(a)
  216
+        data["next"] = "/somewhere/else/?foo=bar"
  217
+        data["comment"] = "This is another comment"
  218
+        response = self.client.post("/post/", data)
  219
+        location = response["Location"]        
  220
+        match = re.search(r"^http://testserver/somewhere/else/\?foo=bar&c=\d+$", location)
  221
+        self.failUnless(match != None, "Unexpected redirect location: %s" % location)
  222
+        

0 notes on commit 6319470

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