blacklist 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ h1. BlackList: dead simple content filtering
2
+
3
+ This library is just a simple implementation of a blacklist to filter content. It comes
4
+ with a set of default words for filtering in config/black_list.yml that were obtained from
5
+ "http://www.noswearing.com":http://www.noswearing.com. You can add or remove from the list
6
+ as necessary. It supports two types of filters currently--exact matches and greedy matches.
7
+ Exact matches will only match if the word is found on its own. Greedy matches will find
8
+ words nested within other words. It will also work out of the box as a Ruby on Rails plugin.
9
+ Just drop it in vendor/plugins and it'll work.
10
+
11
+ Usage is as follows:
12
+
13
+ BlackList.block?("Stupid ass simple.") => true
14
+ BlackList.block?("Squeaky clean.") => false
15
+ BlackList.block?("Assassins!") => false
16
+
17
+ You can also just search for particular sorts of matches:
18
+
19
+ BlackList.greedy?("Stupid ass simple.") => false
20
+ BlackList.exact?("Stupid ass simple.") => true
21
+
22
+ It also supports highlighting flagged words:
23
+
24
+ BlackList.highlight("Stupid ass simple.") => "<code><p>Stupid <strong>ass</strong> simple.</p></code>"
25
+ BlackList.highlight("Squeaky clean.") => "<code><p>Squeaky clean.</p></code>"
@@ -0,0 +1,329 @@
1
+ # List obtained from http://www.noswearing.com/
2
+ ---
3
+ # Exact Matches (only matches a word if it's an exact match)
4
+ - - anus
5
+ - arse
6
+ - arsehole
7
+ - ass
8
+ - ass-hat
9
+ - ass-pirate
10
+ - assbag
11
+ - assbandit
12
+ - assbanger
13
+ - assbite
14
+ - assclown
15
+ - asscock
16
+ - asscracker
17
+ - asses
18
+ - assface
19
+ - assfuck
20
+ - assfucker
21
+ - assgoblin
22
+ - asshat
23
+ - asshead
24
+ - asshole
25
+ - asshopper
26
+ - assjacker
27
+ - asslick
28
+ - asslicker
29
+ - assmonkey
30
+ - assmunch
31
+ - assmuncher
32
+ - assnigger
33
+ - asspirate
34
+ - assshit
35
+ - assshole
36
+ - asssucker
37
+ - asswad
38
+ - asswipe
39
+ - bampot
40
+ - bastard
41
+ - beaner
42
+ - bitch
43
+ - bitchass
44
+ - bitches
45
+ - bitchtits
46
+ - bitchy
47
+ - blow job
48
+ - blowjob
49
+ - bollocks
50
+ - bollox
51
+ - boner
52
+ - brotherfucker
53
+ - bullshit
54
+ - bumblefuck
55
+ - butt plug
56
+ - butt-pirate
57
+ - buttfucka
58
+ - buttfucker
59
+ - camel toe
60
+ - carpetmuncher
61
+ - chinc
62
+ - chink
63
+ - choad
64
+ - chode
65
+ - clit
66
+ - clitface
67
+ - clitfuck
68
+ - clusterfuck
69
+ - cock
70
+ - cockass
71
+ - cockbite
72
+ - cockburger
73
+ - cockface
74
+ - cockfucker
75
+ - cockhead
76
+ - cockjockey
77
+ - cockknoker
78
+ - cockmaster
79
+ - cockmongler
80
+ - cockmongruel
81
+ - cockmonkey
82
+ - cockmuncher
83
+ - cocknose
84
+ - cocknugget
85
+ - cockshit
86
+ - cocksmith
87
+ - cocksmoker
88
+ - cocksucker
89
+ - coochie
90
+ - coochy
91
+ - coon
92
+ - cooter
93
+ - cracker
94
+ - cum
95
+ - cumbubble
96
+ - cumdumpster
97
+ - cumguzzler
98
+ - cumjockey
99
+ - cumslut
100
+ - cumtart
101
+ - cunnie
102
+ - cunnilingus
103
+ - cunt
104
+ - cuntface
105
+ - cunthole
106
+ - cuntlicker
107
+ - cuntrag
108
+ - cuntslut
109
+ - dago
110
+ - damn
111
+ - deggo
112
+ - dick
113
+ - dickbag
114
+ - dickbeaters
115
+ - dickface
116
+ - dickfuck
117
+ - dickfucker
118
+ - dickhead
119
+ - dickhole
120
+ - dickjuice
121
+ - dickmilk
122
+ - dickmonger
123
+ - dicks
124
+ - dickslap
125
+ - dicksucker
126
+ - dickwad
127
+ - dickweasel
128
+ - dickweed
129
+ - dickwod
130
+ - dike
131
+ - dildo
132
+ - dipshit
133
+ - doochbag
134
+ - dookie
135
+ - douche
136
+ - douche-fag
137
+ - douchebag
138
+ - douchewaffle
139
+ - dumass
140
+ - dumb ass
141
+ - dumbass
142
+ - dumbfuck
143
+ - dumbshit
144
+ - dumshit
145
+ - dyke
146
+ - fag
147
+ - fagbag
148
+ - fagfucker
149
+ - faggit
150
+ - faggot
151
+ - faggotcock
152
+ - fagtard
153
+ - fatass
154
+ - fellatio
155
+ - feltch
156
+ - flamer
157
+ - fuck
158
+ - fuckass
159
+ - fuckbag
160
+ - fuckboy
161
+ - fuckbrain
162
+ - fuckbutt
163
+ - fucked
164
+ - fucker
165
+ - fuckersucker
166
+ - fuckface
167
+ - fuckhead
168
+ - fuckhole
169
+ - fuckin
170
+ - fucking
171
+ - fucknut
172
+ - fucknutt
173
+ - fuckoff
174
+ - fucks
175
+ - fuckstick
176
+ - fucktard
177
+ - fuckup
178
+ - fuckwad
179
+ - fuckwit
180
+ - fuckwitt
181
+ - fudgepacker
182
+ - gay
183
+ - gayass
184
+ - gaybob
185
+ - gaydo
186
+ - gayfuck
187
+ - gayfuckist
188
+ - gaylord
189
+ - gaytard
190
+ - gaywad
191
+ - goddamn
192
+ - goddamnit
193
+ - gooch
194
+ - gook
195
+ - gringo
196
+ - guido
197
+ - handjob
198
+ - hard on
199
+ - heeb
200
+ - hell
201
+ - ho
202
+ - hoe
203
+ - homo
204
+ - homodumbshit
205
+ - honkey
206
+ - humping
207
+ - jackass
208
+ - jap
209
+ - jerk off
210
+ - jigaboo
211
+ - jizz
212
+ - jungle bunny
213
+ - junglebunny
214
+ - kike
215
+ - kooch
216
+ - kootch
217
+ - kunt
218
+ - kyke
219
+ - lesbian
220
+ - lesbo
221
+ - lezzie
222
+ - mcfagget
223
+ - mick
224
+ - minge
225
+ - mothafucka
226
+ - motherfucker
227
+ - motherfucking
228
+ - muff
229
+ - muffdiver
230
+ - munging
231
+ - negro
232
+ - nigga
233
+ - nigger
234
+ - niggers
235
+ - niglet
236
+ - nut sack
237
+ - nutsack
238
+ - paki
239
+ - panooch
240
+ - pecker
241
+ - peckerhead
242
+ - penis
243
+ - penisfucker
244
+ - penispuffer
245
+ - piss
246
+ - pissed
247
+ - pissed off
248
+ - pissflaps
249
+ - polesmoker
250
+ - pollock
251
+ - poon
252
+ - poonani
253
+ - poonany
254
+ - poontang
255
+ - porch monkey
256
+ - porchmonkey
257
+ - prick
258
+ - punanny
259
+ - punta
260
+ - pussies
261
+ - pussy
262
+ - pussylicking
263
+ - puto
264
+ - queef
265
+ - queer
266
+ - queerbait
267
+ - queerhole
268
+ - renob
269
+ - rimjob
270
+ - ruski
271
+ - sand nigger
272
+ - sandnigger
273
+ - schlong
274
+ - scrote
275
+ - shit
276
+ - shitass
277
+ - shitbag
278
+ - shitbagger
279
+ - shitbrains
280
+ - shitbreath
281
+ - shitcunt
282
+ - shitdick
283
+ - shitface
284
+ - shitfaced
285
+ - shithead
286
+ - shithole
287
+ - shithouse
288
+ - shitspitter
289
+ - shitstain
290
+ - shitter
291
+ - shittiest
292
+ - shitting
293
+ - shitty
294
+ - shiz
295
+ - shiznit
296
+ - skank
297
+ - skeet
298
+ - skullfuck
299
+ - slut
300
+ - slutbag
301
+ - smeg
302
+ - snatch
303
+ - spic
304
+ - spick
305
+ - splooge
306
+ - tard
307
+ - testicle
308
+ - thundercunt
309
+ - tit
310
+ - titfuck
311
+ - tits
312
+ - tittyfuck
313
+ - twat
314
+ - twatlips
315
+ - twats
316
+ - twatwaffle
317
+ - unclefucker
318
+ - va-j-j
319
+ - vag
320
+ - vagina
321
+ - vjayjay
322
+ - wank
323
+ - wetback
324
+ - whore
325
+ - whorebag
326
+ - whoreface
327
+ - wop
328
+ # Greedy Matches (matches if the word occurs anywhere--including inside other words)
329
+ - - fuck
@@ -0,0 +1,329 @@
1
+ # List obtained from http://www.noswearing.com/
2
+ ---
3
+ # Exact Matches (only matches a word if it's an exact match)
4
+ - - anus
5
+ - arse
6
+ - arsehole
7
+ - ass
8
+ - ass-hat
9
+ - ass-pirate
10
+ - assbag
11
+ - assbandit
12
+ - assbanger
13
+ - assbite
14
+ - assclown
15
+ - asscock
16
+ - asscracker
17
+ - asses
18
+ - assface
19
+ - assfuck
20
+ - assfucker
21
+ - assgoblin
22
+ - asshat
23
+ - asshead
24
+ - asshole
25
+ - asshopper
26
+ - assjacker
27
+ - asslick
28
+ - asslicker
29
+ - assmonkey
30
+ - assmunch
31
+ - assmuncher
32
+ - assnigger
33
+ - asspirate
34
+ - assshit
35
+ - assshole
36
+ - asssucker
37
+ - asswad
38
+ - asswipe
39
+ - bampot
40
+ - bastard
41
+ - beaner
42
+ - bitch
43
+ - bitchass
44
+ - bitches
45
+ - bitchtits
46
+ - bitchy
47
+ - blow job
48
+ - blowjob
49
+ - bollocks
50
+ - bollox
51
+ - boner
52
+ - brotherfucker
53
+ - bullshit
54
+ - bumblefuck
55
+ - butt plug
56
+ - butt-pirate
57
+ - buttfucka
58
+ - buttfucker
59
+ - camel toe
60
+ - carpetmuncher
61
+ - chinc
62
+ - chink
63
+ - choad
64
+ - chode
65
+ - clit
66
+ - clitface
67
+ - clitfuck
68
+ - clusterfuck
69
+ - cock
70
+ - cockass
71
+ - cockbite
72
+ - cockburger
73
+ - cockface
74
+ - cockfucker
75
+ - cockhead
76
+ - cockjockey
77
+ - cockknoker
78
+ - cockmaster
79
+ - cockmongler
80
+ - cockmongruel
81
+ - cockmonkey
82
+ - cockmuncher
83
+ - cocknose
84
+ - cocknugget
85
+ - cockshit
86
+ - cocksmith
87
+ - cocksmoker
88
+ - cocksucker
89
+ - coochie
90
+ - coochy
91
+ - coon
92
+ - cooter
93
+ - cracker
94
+ - cum
95
+ - cumbubble
96
+ - cumdumpster
97
+ - cumguzzler
98
+ - cumjockey
99
+ - cumslut
100
+ - cumtart
101
+ - cunnie
102
+ - cunnilingus
103
+ - cunt
104
+ - cuntface
105
+ - cunthole
106
+ - cuntlicker
107
+ - cuntrag
108
+ - cuntslut
109
+ - dago
110
+ - damn
111
+ - deggo
112
+ - dick
113
+ - dickbag
114
+ - dickbeaters
115
+ - dickface
116
+ - dickfuck
117
+ - dickfucker
118
+ - dickhead
119
+ - dickhole
120
+ - dickjuice
121
+ - dickmilk
122
+ - dickmonger
123
+ - dicks
124
+ - dickslap
125
+ - dicksucker
126
+ - dickwad
127
+ - dickweasel
128
+ - dickweed
129
+ - dickwod
130
+ - dike
131
+ - dildo
132
+ - dipshit
133
+ - doochbag
134
+ - dookie
135
+ - douche
136
+ - douche-fag
137
+ - douchebag
138
+ - douchewaffle
139
+ - dumass
140
+ - dumb ass
141
+ - dumbass
142
+ - dumbfuck
143
+ - dumbshit
144
+ - dumshit
145
+ - dyke
146
+ - fag
147
+ - fagbag
148
+ - fagfucker
149
+ - faggit
150
+ - faggot
151
+ - faggotcock
152
+ - fagtard
153
+ - fatass
154
+ - fellatio
155
+ - feltch
156
+ - flamer
157
+ - fuck
158
+ - fuckass
159
+ - fuckbag
160
+ - fuckboy
161
+ - fuckbrain
162
+ - fuckbutt
163
+ - fucked
164
+ - fucker
165
+ - fuckersucker
166
+ - fuckface
167
+ - fuckhead
168
+ - fuckhole
169
+ - fuckin
170
+ - fucking
171
+ - fucknut
172
+ - fucknutt
173
+ - fuckoff
174
+ - fucks
175
+ - fuckstick
176
+ - fucktard
177
+ - fuckup
178
+ - fuckwad
179
+ - fuckwit
180
+ - fuckwitt
181
+ - fudgepacker
182
+ - gay
183
+ - gayass
184
+ - gaybob
185
+ - gaydo
186
+ - gayfuck
187
+ - gayfuckist
188
+ - gaylord
189
+ - gaytard
190
+ - gaywad
191
+ - goddamn
192
+ - goddamnit
193
+ - gooch
194
+ - gook
195
+ - gringo
196
+ - guido
197
+ - handjob
198
+ - hard on
199
+ - heeb
200
+ - hell
201
+ - ho
202
+ - hoe
203
+ - homo
204
+ - homodumbshit
205
+ - honkey
206
+ - humping
207
+ - jackass
208
+ - jap
209
+ - jerk off
210
+ - jigaboo
211
+ - jizz
212
+ - jungle bunny
213
+ - junglebunny
214
+ - kike
215
+ - kooch
216
+ - kootch
217
+ - kunt
218
+ - kyke
219
+ - lesbian
220
+ - lesbo
221
+ - lezzie
222
+ - mcfagget
223
+ - mick
224
+ - minge
225
+ - mothafucka
226
+ - motherfucker
227
+ - motherfucking
228
+ - muff
229
+ - muffdiver
230
+ - munging
231
+ - negro
232
+ - nigga
233
+ - nigger
234
+ - niggers
235
+ - niglet
236
+ - nut sack
237
+ - nutsack
238
+ - paki
239
+ - panooch
240
+ - pecker
241
+ - peckerhead
242
+ - penis
243
+ - penisfucker
244
+ - penispuffer
245
+ - piss
246
+ - pissed
247
+ - pissed off
248
+ - pissflaps
249
+ - polesmoker
250
+ - pollock
251
+ - poon
252
+ - poonani
253
+ - poonany
254
+ - poontang
255
+ - porch monkey
256
+ - porchmonkey
257
+ - prick
258
+ - punanny
259
+ - punta
260
+ - pussies
261
+ - pussy
262
+ - pussylicking
263
+ - puto
264
+ - queef
265
+ - queer
266
+ - queerbait
267
+ - queerhole
268
+ - renob
269
+ - rimjob
270
+ - ruski
271
+ - sand nigger
272
+ - sandnigger
273
+ - schlong
274
+ - scrote
275
+ - shit
276
+ - shitass
277
+ - shitbag
278
+ - shitbagger
279
+ - shitbrains
280
+ - shitbreath
281
+ - shitcunt
282
+ - shitdick
283
+ - shitface
284
+ - shitfaced
285
+ - shithead
286
+ - shithole
287
+ - shithouse
288
+ - shitspitter
289
+ - shitstain
290
+ - shitter
291
+ - shittiest
292
+ - shitting
293
+ - shitty
294
+ - shiz
295
+ - shiznit
296
+ - skank
297
+ - skeet
298
+ - skullfuck
299
+ - slut
300
+ - slutbag
301
+ - smeg
302
+ - snatch
303
+ - spic
304
+ - spick
305
+ - splooge
306
+ - tard
307
+ - testicle
308
+ - thundercunt
309
+ - tit
310
+ - titfuck
311
+ - tits
312
+ - tittyfuck
313
+ - twat
314
+ - twatlips
315
+ - twats
316
+ - twatwaffle
317
+ - unclefucker
318
+ - va-j-j
319
+ - vag
320
+ - vagina
321
+ - vjayjay
322
+ - wank
323
+ - wetback
324
+ - whore
325
+ - whorebag
326
+ - whoreface
327
+ - wop
328
+ # Greedy Matches (matches if the word occurs anywhere--including inside other words)
329
+ - - fuck
@@ -0,0 +1,133 @@
1
+ #:title: BlackList RDoc Documentation
2
+ #
3
+ # = BlackList: dead simple content filtering
4
+ #
5
+ # This library is just a simple implementation of a blacklist to filter content.
6
+ # It comes with a set of default words for filtering in config/black_list.yml that
7
+ # were obtained from http://www.noswearing.com. You can add or remove from the list
8
+ # as necessary. It supports two types of filters currently--exact matches and greedy
9
+ # matches.Exact matches will only match if the word is found on its own. Greedy
10
+ # matches will find words nested within other words. It will also work out of the
11
+ # box as a Ruby on Rails plugin. Just drop it in vendor/plugins and it'll work.
12
+ #
13
+ # Usage is as follows:
14
+ #
15
+ # BlackList.block?("Stupid ass simple.") => true
16
+ # BlackList.block?("Squeaky clean.") => false
17
+ # BlackList.block?("Assassins!") => false
18
+ #
19
+ # You can also just search for particular sorts of matches:
20
+ #
21
+ # BlackList.greedy?("Stupid ass simple.") => false
22
+ # BlackList.exact?("Stupid ass simple.") => true
23
+ #
24
+ # It also supports highlighting flagged words:
25
+ #
26
+ # BlackList.highlight("Stupid ass simple.") => "<code><p>Stupid <strong>ass</strong> simple.</p></code>"
27
+ # BlackList.highlight("Squeaky clean.") => "<code><p>Squeaky clean.</p></code>"
28
+
29
+ require 'yaml'
30
+ require 'rubygems'
31
+ require 'RedCloth'
32
+ require 'singleton'
33
+
34
+ class BlackList
35
+ include Singleton
36
+ attr_accessor :exact, :greedy
37
+
38
+ # Redirects all method calls made directly on BlackList to
39
+ # BlackList.instance. For example:
40
+ #
41
+ # BlackList.greedy?("foo") => BlackList.instance.greedy?("foo")
42
+ def self.method_missing(method, *args) #:nodoc:
43
+ self.instance.send(method, *args) unless method == :instance
44
+ end
45
+
46
+ # Loads blacklist words from black_list.yml and removes any
47
+ # nested greedy words. This is always called implicitly due
48
+ # to the fact that BlackList is a Singleton. As such, there
49
+ # is only ever one instance.
50
+ def initialize #:nodoc:
51
+ load_words!
52
+ trim_greedy_words!
53
+ end
54
+
55
+ # Check the supplied text to see whether it contains a blacklisted
56
+ # word and should be blocked.
57
+ def block?(text)
58
+ greedy?(text) or exact?(text)
59
+ end
60
+
61
+ # Check the supplied text to see whether it contains an exact
62
+ # blacklisted word.
63
+ def exact?(text)
64
+ check(text, :exact, @exact)
65
+ end
66
+
67
+ # Check the supplied text to see whether it contains a greedy
68
+ # blacklisted word.
69
+ def greedy?(text)
70
+ check(text, :greedy, @greedy)
71
+ end
72
+
73
+ # Get the supplied text in HTML format with any blacklisted
74
+ # words bolded. Text is passed through a Textile markup
75
+ # processor (RedCloth).
76
+ def highlight(text)
77
+ return text if text !~ /\S/
78
+
79
+ text = highlight_words!(text, :exact, @exact)
80
+ text = highlight_words!(text, :greedy, @greedy)
81
+
82
+ RedCloth.new(text).to_html
83
+ end
84
+
85
+ private
86
+ # Removes words that are supersets of other @greedy words.
87
+ # For example, "assassin" would be removed if it was a
88
+ # @greedy word and another @greedy word, "ass" existed.
89
+ def trim_greedy_words!
90
+ @greedy.each do |word|
91
+ @greedy.delete_if{ |other_word| other_word.match(word) && word != other_word }
92
+ end
93
+ end
94
+
95
+ # Return text with Textile markup for bolding all blacklisted
96
+ # words of the designated match kind.
97
+ def highlight_words!(text, kind, words)
98
+ words.each do |word|
99
+ if kind == :greedy
100
+ text.gsub!(/(#{word})+/i, '*\1*')
101
+ else
102
+ text.gsub!(/\b(#{word})\b/i, '*\1*')
103
+ end
104
+ end unless words.nil?
105
+ text
106
+ end
107
+
108
+ # Check the supplied text for any of the supplied words
109
+ # using the designated match kind.
110
+ def check(text, kind, words) #:doc:
111
+ return false if words.nil?
112
+ words.each do |word|
113
+ return true if (kind == :greedy ? greedy_match?(text, word) : exact_match?(text, word))
114
+ end
115
+ false
116
+ end
117
+
118
+ # Check for exact matches of word in the supplied text.
119
+ def exact_match?(text, word) #:doc:
120
+ text =~ /\b#{word}\b/i
121
+ end
122
+
123
+ # Check for greedy matches of word in the supplied text.
124
+ def greedy_match?(text, word) #:doc:
125
+ text =~ /(#{word})+/i
126
+ end
127
+
128
+ # Load all blacklisted words from black_list.yml and save
129
+ # then in @exact and @greedy.
130
+ def load_words!
131
+ @exact, @greedy = YAML::load(File.read(File.join(File.dirname(__FILE__), "../config/blacklists/#{I18n.locale}.yml")))
132
+ end
133
+ end
@@ -0,0 +1,203 @@
1
+ require File.join(File.dirname(__FILE__), '../lib/black_list')
2
+
3
+ describe BlackList do
4
+ before(:all) do
5
+ @clean_phrase = "This is a clean phrase."
6
+ @greedy_phrase = "Oh, fuck!"
7
+ @exact_phrase = "Let's kick some ass!"
8
+ @nested_greedy_phrase = "I have had it with these motherfucking snakes on this motherfucking plane!"
9
+ @nested_exact_phrase = "Watch out for the assassin!"
10
+ @capcase_exact_phrase = "Let's kick some AsS!"
11
+ @capcase_greedy_phrase = "Oh, FuCk!"
12
+ @multiple_phrase = "Oh, fuck! I have had it with these motherfucking snakes on this motherfucking plane!"
13
+ end
14
+
15
+ it "should have an array of words in @greedy" do
16
+ BlackList.greedy.should be_kind_of(Array)
17
+ end
18
+
19
+ it "should have an array of words in @exact" do
20
+ BlackList.exact.should be_kind_of(Array)
21
+ end
22
+
23
+ it "should set @greedy with supplied values" do
24
+ lambda { BlackList.greedy = ["foo"] }.should change(BlackList, :greedy).from(nil).to(["foo"])
25
+ end
26
+
27
+ it "should set @exact with supplied values" do
28
+ lambda { BlackList.exact = ["foo"] }.should change(BlackList, :exact).from(nil).to(["foo"])
29
+ end
30
+
31
+ describe ".load_words!" do
32
+ before(:each) do
33
+ BlackList.greedy = nil
34
+ BlackList.exact = nil
35
+ end
36
+
37
+ it "should load exact blacklist words" do
38
+ lambda { BlackList.send(:load_words!) }.should change(BlackList, :exact)
39
+ end
40
+
41
+ it "should load greedy blacklist words" do
42
+ lambda { BlackList.send(:load_words!) }.should change(BlackList, :greedy)
43
+ end
44
+ end
45
+
46
+ describe ".block?" do
47
+ it "should not block if no words are found" do
48
+ BlackList.block?(@clean_phrase).should be_false
49
+ end
50
+
51
+ it "should find exact matches" do
52
+ BlackList.block?(@exact_phrase).should be_true
53
+ end
54
+
55
+ it "should find greedy matches" do
56
+ BlackList.block?(@greedy_phrase).should be_true
57
+ end
58
+ end
59
+
60
+ describe ".exact?" do
61
+ it "should only find words in the EXACT list" do
62
+ BlackList.exact?(BlackList.greedy.join(" ")).should be_false
63
+ end
64
+
65
+ it "should find exact matches" do
66
+ BlackList.exact?(@exact_phrase).should be_true
67
+ end
68
+
69
+ it "should not find nested words" do
70
+ BlackList.exact?(@assassin_phrase).should be_false
71
+ end
72
+
73
+ it "should be case insensitive" do
74
+ BlackList.exact?(@capcase_exact_phrase).should be_true
75
+ end
76
+ end
77
+
78
+ describe ".greedy?" do
79
+ it "should find exact words" do
80
+ BlackList.greedy?(@greedy_phrase).should be_true
81
+ end
82
+
83
+ it "should find nested words" do
84
+ BlackList.greedy?(@nested_greedy_phrase).should be_true
85
+ end
86
+
87
+ it "should be case insensitive" do
88
+ BlackList.greedy?(@capcase_greedy_phrase).should be_true
89
+ end
90
+ end
91
+
92
+ describe ".highlight" do
93
+ it "should return HTML" do
94
+ BlackList.highlight(@clean_phrase).should =~ /<p>.*?<\/p>/
95
+ end
96
+
97
+ it "should return a single set of <strong> tags when only one word is flagged" do
98
+ BlackList.highlight(@greedy_phrase).should =~ /((.*?)(<strong>.*?<\/strong>)){1}/
99
+ end
100
+
101
+ it "should return a set of <strong> tags for each blacklisted word" do
102
+ BlackList.highlight(@multiple_phrase).should =~ /((.*?)(<strong>.*?<\/strong>)){3}/
103
+ end
104
+
105
+ it "should not return <strong> tags in a clean phrase" do
106
+ BlackList.highlight(@clean_phrase).should_not =~ /((.*?)(<strong>.*?<\/strong>)){1}/
107
+ end
108
+
109
+ it "should not endlessly replace greedy words when a superset greedy word exists" do
110
+ @nested_greedy_phrase = "A test where fag is mentioned along with faggot."
111
+ BlackList.highlight(@nested_greedy_phrase).should =~ /((.*?)(<strong>.*?<\/strong>)){2}/
112
+ end
113
+ end
114
+
115
+ describe ".highlight_words!" do
116
+ it "should not alter text if the supplied array is nil when kind is :exact" do
117
+ BlackList.highlight_words!("This should be highlighted.", :exact, nil).should_not =~ /((.*?)(\*.*?\*)){1}/
118
+ end
119
+
120
+ it "should not alter text if the supplied array is nil when kind is :greedy" do
121
+ BlackList.highlight_words!("This should be highlighted.", :greedy, nil).should_not =~ /((.*?)(\*.*?\*)){1}/
122
+ end
123
+
124
+ it "should not alter text if the supplied array is empty when kind is :exact" do
125
+ BlackList.highlight_words!("This should be highlighted.", :exact, []).should_not =~ /((.*?)(\*.*?\*)){1}/
126
+ end
127
+
128
+ it "should not alter text if the supplied array is empty when kind is :greedy" do
129
+ BlackList.highlight_words!("This should be highlighted.", :greedy, []).should_not =~ /((.*?)(\*.*?\*)){1}/
130
+ end
131
+
132
+ it "should use supplied array when kind is :exact" do
133
+ BlackList.highlight_words!("This should this be highlighted.", :exact, ["this"]).should =~ /((.*?)(\*.*?\*)){1}/
134
+ end
135
+
136
+ it "should use supplied array when kind is :greedy" do
137
+ BlackList.highlight_words!("This should be highlighted.", :greedy, ["highlight"]).should =~ /((.*?)(\*.*?\*)){1}/
138
+ end
139
+ end
140
+
141
+ describe ".check" do
142
+ it "should return false if supplied words equal nil when kind is :greedy" do
143
+ BlackList.send(:check, "This is a greedy test.", :greedy, nil).should be_false
144
+ end
145
+
146
+ it "should return false if supplied words equal nil when kind is :exact" do
147
+ BlackList.send(:check, "This is a greedy test.", :exact, nil).should be_false
148
+ end
149
+
150
+ it "should find greedy words when kind is :greedy" do
151
+ BlackList.send(:check, "This is a greedy test.", :greedy, ["greed"]).should be_true
152
+ end
153
+
154
+ it "should find exact words when kind is :greedy" do
155
+ BlackList.send(:check, "This is a greedy test.", :greedy, ["greedy"]).should be_true
156
+ end
157
+
158
+ it "should find exact words when kind is :exact" do
159
+ BlackList.send(:check, "This is a greedy test.", :exact, ["greedy"]).should be_true
160
+ end
161
+
162
+ it "should not find greedy words when kind is :exact" do
163
+ BlackList.send(:check, "This is a greedy test.", :exact, ["greed"]).should be_false
164
+ end
165
+ end
166
+
167
+ describe ".exact_match?" do
168
+ it "should not be nil for exact matches" do
169
+ BlackList.send(:exact_match?, "This is a greedy test.", "greedy").should_not be_nil
170
+ end
171
+
172
+ it "should be nil for greedy matches" do
173
+ BlackList.send(:exact_match?, "This is a greedy test.", "greed").should be_nil
174
+ end
175
+
176
+ it "should be nil for no matches" do
177
+ BlackList.send(:exact_match?, "This is a test.", "greedy").should be_nil
178
+ end
179
+ end
180
+
181
+ describe ".greedy_match?" do
182
+ it "should not be nil for greedy matches" do
183
+ BlackList.send(:greedy_match?, "This is a greedy test.", "greed").should_not be_nil
184
+ end
185
+
186
+ it "should not be nil for exact matches" do
187
+ BlackList.send(:greedy_match?, "This is a greedy test.", "greedy").should_not be_nil
188
+ end
189
+
190
+ it "should be nil for no matches" do
191
+ BlackList.send(:greedy_match?, "This is a test.", "greedy").should be_nil
192
+ end
193
+ end
194
+
195
+ describe ".trim_greedy_words!" do
196
+ it "should remove words that are supersets of other greedy words" do
197
+ BlackList.greedy = ["foo", "foobar", "foobarbaz"]
198
+ BlackList.send(:trim_greedy_words!)
199
+ BlackList.greedy.first.should == "foo"
200
+ BlackList.greedy.size.should == 1
201
+ end
202
+ end
203
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blacklist
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Joel Watson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-10 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: RedCloth
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ description: BlackList is a Ruby library offering simple content filtering via blacklisted words.
26
+ email: github@watsonian.otherinbox.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - README.textile
35
+ - lib/black_list.rb
36
+ - config/blacklists/en.yml
37
+ - config/blacklists/fr.yml
38
+ has_rdoc: true
39
+ homepage: http://github.com/watsonian/blacklist
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.5
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: A simple content filtering system
66
+ test_files:
67
+ - spec/black_list_spec.rb