Code

Ticket #8794: t8794.diff

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

Fix for the actual Scunthorpe bug.

Line 
1diff -r 1a1428431cca django/contrib/comments/forms.py
2--- a/django/contrib/comments/forms.py  Wed Oct 06 22:56:52 2010 +0000
3+++ b/django/contrib/comments/forms.py  Thu Oct 07 12:30:15 2010 +0100
4@@ -1,3 +1,4 @@
5+import re
6 import time
7 import datetime
8 
9@@ -168,7 +169,8 @@
10         """
11         comment = self.cleaned_data["comment"]
12         if settings.COMMENTS_ALLOW_PROFANITIES == False:
13-            bad_words = [w for w in settings.PROFANITIES_LIST if w in comment.lower()]
14+            bad_words = [w for w in settings.PROFANITIES_LIST
15+                         if re.search(r'\b%s\b' % w, comment, flags=re.IGNORECASE)]
16             if bad_words:
17                 plural = len(bad_words) > 1
18                 raise forms.ValidationError(ungettext(
19diff -r 1a1428431cca tests/regressiontests/comment_tests/tests/comment_form_tests.py
20--- a/tests/regressiontests/comment_tests/tests/comment_form_tests.py   Wed Oct 06 22:56:52 2010 +0000
21+++ b/tests/regressiontests/comment_tests/tests/comment_form_tests.py   Thu Oct 07 12:30:15 2010 +0100
22@@ -72,6 +72,10 @@
23         f = CommentForm(a, data=dict(d, comment="What a rooster!"))
24         self.failIf(f.is_valid())
25 
26+        # Check for Scunthorpe problem
27+        f = CommentForm(a, data=dict(d, comment="What a brooster!"))
28+        self.failUnless(f.is_valid())
29+
30         # Now with COMMENTS_ALLOW_PROFANITIES on
31         settings.COMMENTS_ALLOW_PROFANITIES = True
32         f = CommentForm(a, data=dict(d, comment="What a rooster!"))