Ticket #12151: 12151_2.diff

File 12151_2.diff, 2.0 KB (added by thejaswi_puthraya, 5 years ago)

patch and tests

  • django/contrib/comments/views/utils.py

    diff --git a/django/contrib/comments/views/utils.py b/django/contrib/comments/views/utils.py
    index c5c900d..8b729d2 100644
    a b def confirmation_view(template, doc="Display a confirmation view."): 
    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

    diff --git a/tests/regressiontests/comment_tests/tests/comment_view_tests.py b/tests/regressiontests/comment_tests/tests/comment_view_tests.py
    index 192131b..bb0b46e 100644
    a b class CommentViewTests(CommentTestCase): 
    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        
    223  No newline at end of file
     222
     223    def testCommentDoneReSubmitWithInvalidParams(self):
     224        """
     225        If the comment-done url is resubmitted with some invalid data
     226        ie mainly some non-integer, then a UnicodeEncodeError (a sub-class
     227        of ValueError).
     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        new_location = location + u"\ufffd"
     235        x = lambda : self.client.get(new_location)
     236        try:
     237            self.assertRaises(ValueError, x)
     238        except AssertionError:
     239            # An exception shouldn't be raised.
     240            # Hope there was a assertNotRaises
     241            pass
Back to Top