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
This commit is contained in:
Karen Tracey 2010-03-05 20:17:52 +00:00
parent eb11229ba7
commit 80545c3685
2 changed files with 16 additions and 2 deletions

View File

@ -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},

View File

@ -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)
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)