diff --git a/django/contrib/comments/views/utils.py b/django/contrib/comments/views/utils.py index c5c900d47f..8b729d2d95 100644 --- a/django/contrib/comments/views/utils.py +++ b/django/contrib/comments/views/utils.py @@ -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}, diff --git a/tests/regressiontests/comment_tests/tests/comment_view_tests.py b/tests/regressiontests/comment_tests/tests/comment_view_tests.py index 192131bf0c..f33a752843 100644 --- a/tests/regressiontests/comment_tests/tests/comment_view_tests.py +++ b/tests/regressiontests/comment_tests/tests/comment_view_tests.py @@ -219,4 +219,18 @@ class CommentViewTests(CommentTestCase): 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 + + 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)