summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/contrib/comments/views/utils.py3
-rw-r--r--tests/regressiontests/comment_tests/tests/comment_view_tests.py13
2 files changed, 15 insertions, 1 deletions
diff --git a/django/contrib/comments/views/utils.py b/django/contrib/comments/views/utils.py
index a37c555e78..c5c900d47f 100644
--- a/django/contrib/comments/views/utils.py
+++ b/django/contrib/comments/views/utils.py
@@ -25,7 +25,8 @@ def next_redirect(data, default, default_view, **get_kwargs):
if next is None:
next = urlresolvers.reverse(default_view)
if get_kwargs:
- next += "?" + urllib.urlencode(get_kwargs)
+ joiner = ('?' in next) and '&' or '?'
+ next += joiner + urllib.urlencode(get_kwargs)
return HttpResponseRedirect(next)
def confirmation_view(template, doc="Display a confirmation view."):
diff --git a/tests/regressiontests/comment_tests/tests/comment_view_tests.py b/tests/regressiontests/comment_tests/tests/comment_view_tests.py
index 0c975116ef..9183888d5c 100644
--- a/tests/regressiontests/comment_tests/tests/comment_view_tests.py
+++ b/tests/regressiontests/comment_tests/tests/comment_view_tests.py
@@ -196,3 +196,16 @@ class CommentViewTests(CommentTestCase):
self.assertTemplateUsed(response, "comments/posted.html")
self.assertEqual(response.context[0]["comment"], Comment.objects.get(pk=1))
+ def testCommentNextWithQueryString(self):
+ """
+ The `next` key needs to handle already having a query string (#10585)
+ """
+ a = Article.objects.get(pk=1)
+ data = self.getValidData(a)
+ data["next"] = "/somewhere/else/?foo=bar"
+ data["comment"] = "This is another comment"
+ response = self.client.post("/post/", data)
+ location = response["Location"]
+ match = re.search(r"^http://testserver/somewhere/else/\?foo=bar&c=\d+$", location)
+ self.failUnless(match != None, "Unexpected redirect location: %s" % location)
+ \ No newline at end of file