Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 80545c3685c29854990eaf17a96fc65d428f620f 1 parent eb11229
@kmtracey kmtracey authored
View
2  django/contrib/comments/views/utils.py
@@ -39,7 +39,7 @@ def confirmed(request):
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},
View
16 tests/regressiontests/comment_tests/tests/comment_view_tests.py
@@ -219,4 +219,18 @@ def testCommentNextWithQueryString(self):
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)
-
+
+ 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)
Please sign in to comment.
Something went wrong with that request. Please try again.