Ticket #13411: comment-with-query-string-and-anchor-with-unittests-doc.diff

File comment-with-query-string-and-anchor-with-unittests-doc.diff, 1.8 KB (added by David Novakovic, 14 years ago)
  • django/contrib/comments/views/utils.py

    diff -r 7fca308bbf07 django/contrib/comments/views/utils.py
    a b  
    2525    if next is None:
    2626        next = urlresolvers.reverse(default_view)
    2727    if get_kwargs:
     28        if '#' in next:
     29            tmp = next.rsplit('#', 1)
     30            next = tmp[0]
     31            anchor = '#' + tmp[1]
     32        else:
     33            anchor = ''
     34
    2835        joiner = ('?' in next) and '&' or '?'
    29         next += joiner + urllib.urlencode(get_kwargs)
     36        next += joiner + urllib.urlencode(get_kwargs) + anchor
    3037    return HttpResponseRedirect(next)
    3138
    3239def confirmation_view(template, doc="Display a confirmation view."):
  • tests/regressiontests/comment_tests/tests/comment_view_tests.py

    diff -r 7fca308bbf07 tests/regressiontests/comment_tests/tests/comment_view_tests.py
    a b  
    251251        broken_location = location + u"\ufffd"
    252252        response = self.client.get(broken_location)
    253253        self.assertEqual(response.status_code, 200)
     254       
     255    def testCommentNextWithQueryStringAndAnchor(self):
     256        """
     257        The `next` key needs to handle already having an anchor (#13664)
     258        """
     259        a = Article.objects.get(pk=1)
     260        data = self.getValidData(a)
     261        data["next"] = "/somewhere/else/?foo=bar#baz"
     262        data["comment"] = "This is another comment"
     263        response = self.client.post("/post/", data)
     264        location = response["Location"]
     265        match = re.search(r"^http://testserver/somewhere/else/\?foo=bar&c=\d+#baz$", location)
     266        self.failUnless(match != None, "Unexpected redirect location: %s" % location)
    254267
     268
Back to Top