Will, we found the bad word filter with 3.20.09 did not suit our needs. For example Assume, pass, would get changed to pfannyume and ppfanny.
A few posts bad I started a thread about the bad word filter (actually two, but that was my fault. I made the following changes to the source so that pass, assume, for example are not filtered out. The source implementation uses a straight forward string replace. With the use of regular expression you can hone your results. I hope the moderators forgive me if I post this solution again. It is my hope the badword filter could really be improved. A straight forward string.replace method is not your best choice. Here is the function that will create the Regex object for you:
Private Function BuildRegex(ByVal badWord As String) As System.Text.RegularExpressions.Regex
'***************************************************************
'09-17-07 improvement to bad word filter via regular expressions
'for more precision - jfs.
Const RegexMetaCharacters As String = "(\[|\\|\^|\$|\.|\||\?|\*|\+|\(|\))"
Dim filter As StringBuilder
Dim exp As String = String.Empty
Dim wordCapture As String = String.Empty
Dim rx As Regex = Nothing
'(?i)([^a-zA-Z<>&;\s]BADWORD[^a-zA-Z<>&;\s]|\bBADWORD\B)
If (Regex.IsMatch(badWord, RegexMetaCharacters)) Then
wordCapture = Regex.Escape(badWord)
'
filter = New StringBuilder(50)
filter.Append("(?i)([^a-zA-Z<>&;\s]")
filter.Append(wordCapture)
filter.Append("[^a-zA-Z<>&;\s]|\b")
filter.Append(wordCapture)
filter.Append("\B)")
'
Else
'(?i)([^a-zA-Z<>&;\s]BADWORD[^a-zA-Z<>&;]|\bBADWORD\b)
wordCapture = badWord
'
filter = New StringBuilder(50)
filter.Append("(?i)([^a-zA-Z<>&;\s]")
filter.Append(wordCapture)
filter.Append("[^a-zA-Z<>&;\s]|\b]")
filter.Append(wordCapture)
filter.Append("\b)")
'
End If
'
exp = filter.ToString().Trim()
'
Return New Regex(exp)
'
End Function
Then with the two functions in the WordFilterController, I do this:
objFilterWord = CType(colFilterWord.Item(intCount), FilterWordInfo)
'
If objFilterWord.CreatedOn > TimeStamp Then
'
Dim rx As Regex = BuildRegex(objFilterWord.BadWord)
'
If (rx.IsMatch(Text)) Then
Text = rx.Replace(Text, objFilterWord.ReplacedWord)
End If
End If
This will avoid inadvertant replacements and possible attempts to subvert it. For example,
BADWORD
_BADWORD7
7BADWORD!
"BADWORD"
$BADWORD!,
and not eat up white space around it so that a replace inadvertantly concatenates the previous or following word.