Commit 80545c36 authored by Karen Tracey's avatar Karen Tracey
Browse files

Fixed #12151: Ensured the comments code does not cause a server error when a...

Fixed #12151: Ensured the comments code does not cause a server error when a request comes in for a comment specifying an invalid primary key value. Thanks thejaswi_puthraya.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@12681 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent eb11229b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ def confirmation_view(template, doc="Display a confirmation view."):
        if 'c' in request.GET:
            try:
                comment = comments.get_model().objects.get(pk=request.GET['c'])
            except ObjectDoesNotExist:
            except (ObjectDoesNotExist, ValueError):
                pass
        return render_to_response(template,
            {'comment': comment},
+15 −1
Original line number Diff line number Diff line
@@ -220,3 +220,17 @@ class CommentViewTests(CommentTestCase):
        match = re.search(r"^http://testserver/somewhere/else/\?foo=bar&c=\d+$", location)
        self.failUnless(match != None, "Unexpected redirect location: %s" % location)

    def testCommentDoneReSubmitWithInvalidParams(self):
        """
        Tests that attempting to retrieve the location specified in the 
        post redirect, after adding some invalid data to the expected 
        querystring it ends with, doesn't cause a server error.
        """
        a = Article.objects.get(pk=1)
        data = self.getValidData(a)
        data["comment"] = "This is another comment"
        response = self.client.post("/post/", data)
        location = response["Location"]
        broken_location = location + u"\ufffd"
        response = self.client.get(broken_location)
        self.assertEqual(response.status_code, 200)