Ticket #8794: t8794.diff

File t8794.diff, 1.5 KB (added by lukeplant, 4 years ago)

Fix for the actual Scunthorpe bug.

  • django/contrib/comments/forms.py

    diff -r 1a1428431cca django/contrib/comments/forms.py
    a b  
     1import re
    12import time
    23import datetime
    34
     
    168169        """
    169170        comment = self.cleaned_data["comment"]
    170171        if settings.COMMENTS_ALLOW_PROFANITIES == False:
    171             bad_words = [w for w in settings.PROFANITIES_LIST if w in comment.lower()]
     172            bad_words = [w for w in settings.PROFANITIES_LIST
     173                         if re.search(r'\b%s\b' % w, comment, flags=re.IGNORECASE)]
    172174            if bad_words:
    173175                plural = len(bad_words) > 1
    174176                raise forms.ValidationError(ungettext(
  • tests/regressiontests/comment_tests/tests/comment_form_tests.py

    diff -r 1a1428431cca tests/regressiontests/comment_tests/tests/comment_form_tests.py
    a b  
    7272        f = CommentForm(a, data=dict(d, comment="What a rooster!"))
    7373        self.failIf(f.is_valid())
    7474
     75        # Check for Scunthorpe problem
     76        f = CommentForm(a, data=dict(d, comment="What a brooster!"))
     77        self.failUnless(f.is_valid())
     78
    7579        # Now with COMMENTS_ALLOW_PROFANITIES on
    7680        settings.COMMENTS_ALLOW_PROFANITIES = True
    7781        f = CommentForm(a, data=dict(d, comment="What a rooster!"))
Back to Top