Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsForumForumBadword filter badBadword filter bad
Previous
 
Next
New Post
9/19/2007 9:23 AM
 

The forums badword filter is unuseable in its present state.  Here is an implementation that will not substitute "fanny" for assume -> fannyume or password -> pfannyword, etc...

'
                    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

 

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

            If (Regex.IsMatch(badWord, RegexMetaCharacters)) Then
                '(?i)(\bBADWORD\B|(\d?)BADWORD(\d?)(\B|\b)[^a-zA-Z&;<])
                wordCapture = Regex.Escape(badWord)
                '
                filter = New StringBuilder(50)
                filter.Append("(?i)(\b")
                filter.Append(wordCapture)
                filter.Append("\B|(\d?)")
                filter.Append(wordCapture)
                filter.Append("(\d?)(\B|\b)[^a-zA-Z&;<])")
                '
            Else
                '(?i)(\bBADWORD\b|(\d?)BADWORD(\d?)(\B|\b)[^a-zA-Z&;<])
                wordCapture = badWord
                '
                filter = New StringBuilder(50)
                filter.Append("(?i)(\b")
                filter.Append(wordCapture)
                filter.Append("\b|(\d?)")
                filter.Append(wordCapture)
                filter.Append("(\d?)(\B|\b)[^a-zA-Z&;<])")
                '
            End If
            '
            exp = filter.ToString().Trim()
            '
            Return New Regex(exp)
            '
        End Function

 
New Post
9/19/2007 4:56 PM
 

Update. The previous will incorrectly capture [a-zA-Z]BadWord, for example land mass (you know where the word is).  here's the update:

 

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

 
New Post
9/23/2007 4:30 PM
 

pattern update:

BADWORD FILTER:

Non-escaped words:
(?i)(\b****\b|[0-9]****|****[0-9])

Escaped words:
(?i)(\b****\B|[0-9]****|****[0-9])

 
New Post
9/24/2007 7:19 PM
 

It is necessary to provide adjustments:

 

BADWORD FILTER:

Non-escaped words:
(?i)(\b****\b|[0-9]****|****[0-9])

Escaped words:
(?i)(\b****\B|[0-9]****|****[0-9])

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsForumForumBadword filter badBadword filter bad


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out