Skip to content

Commit 215615a

Browse files
committed
[1.1.X] 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.
r12681 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12682 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent b5a2f64 commit 215615a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

django/contrib/comments/views/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def confirmed(request):
3939
if 'c' in request.GET:
4040
try:
4141
comment = comments.get_model().objects.get(pk=request.GET['c'])
42-
except ObjectDoesNotExist:
42+
except (ObjectDoesNotExist, ValueError):
4343
pass
4444
return render_to_response(template,
4545
{'comment': comment},

tests/regressiontests/comment_tests/tests/comment_view_tests.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,18 @@ def testCommentNextWithQueryString(self):
219219
location = response["Location"]
220220
match = re.search(r"^http://testserver/somewhere/else/\?foo=bar&c=\d+$", location)
221221
self.failUnless(match != None, "Unexpected redirect location: %s" % location)
222-
222+
223+
def testCommentDoneReSubmitWithInvalidParams(self):
224+
"""
225+
Tests that attempting to retrieve the location specified in the
226+
post redirect, after adding some invalid data to the expected
227+
querystring it ends with, doesn't cause a server error.
228+
"""
229+
a = Article.objects.get(pk=1)
230+
data = self.getValidData(a)
231+
data["comment"] = "This is another comment"
232+
response = self.client.post("/post/", data)
233+
location = response["Location"]
234+
broken_location = location + u"\ufffd"
235+
response = self.client.get(broken_location)
236+
self.assertEqual(response.status_code, 200)

0 commit comments

Comments
 (0)