Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #12151: Ensured the comments code does not cause a serv…

…er 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
  • Loading branch information...
commit 215615ad58160320ae02d938c85f323cf2c92793 1 parent b5a2f64
Karen Tracey authored March 05, 2010
2  django/contrib/comments/views/utils.py
@@ -39,7 +39,7 @@ def confirmed(request):
39 39
         if 'c' in request.GET:
40 40
             try:
41 41
                 comment = comments.get_model().objects.get(pk=request.GET['c'])
42  
-            except ObjectDoesNotExist:
  42
+            except (ObjectDoesNotExist, ValueError):
43 43
                 pass
44 44
         return render_to_response(template,
45 45
             {'comment': comment},
16  tests/regressiontests/comment_tests/tests/comment_view_tests.py
@@ -219,4 +219,18 @@ def testCommentNextWithQueryString(self):
219 219
         location = response["Location"]        
220 220
         match = re.search(r"^http://testserver/somewhere/else/\?foo=bar&c=\d+$", location)
221 221
         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 notes on commit 215615a

Please sign in to comment.
Something went wrong with that request. Please try again.