obscenity-plus 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e372fa6a81928b0052940a66549255cb6d31c9086c660bcc6263cf105b2d44f5
4
+ data.tar.gz: 12def6afadcb1d3e18e1843f5740c834e953378e8f70438d00e32c4b9b0a2cc0
5
+ SHA512:
6
+ metadata.gz: ec978321c46dc22d603c0127dc966ecb4f24ed66c376024ff275f98f48ffd9a48768fc69f63fe1c05bf9fd470969198f1dfb36a7fd2d79c4d595985d69e891c6
7
+ data.tar.gz: 57aa32b94c376281eeee8bfbe01dfd4a57bf2c422c75d115e9de818e3684df9fbb9537d5e9e5975f665c203ba80ad68bbe4e07cca269419e47204df5ca90d995
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2025 Ropetow
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,297 @@
1
+ # NOTE: This is a forked project.
2
+
3
+ # Obscenity-plus: A work in progress.
4
+
5
+ Obscenity is a profanity filter gem for Ruby/Rubinius, Rails (through ActiveModel), and Rack middleware.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'obscenity-plus'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```ruby
18
+ bundle install
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```ruby
24
+ gem install obscenity-plus
25
+ ```
26
+
27
+ ## Compatibility
28
+
29
+ Obscenity is compatible is a work in progress. Aiming for rails 8+ and ruby 3+.
30
+
31
+ ## Using Obscenity
32
+
33
+ The following methods are available to use with Obscenity:
34
+
35
+ ### Configuration
36
+
37
+ `Obscenity.configure(&block)` allows you to set custom global configuration options. Available options are:
38
+
39
+ `config.blacklist` accepts the following values:
40
+
41
+ - An array with words
42
+ - A string representing a path to a yml file
43
+ - A Pathname object with a path to a yml file
44
+
45
+ `config.whitelist` accepts the following values:
46
+
47
+ - An array with words
48
+ - A string representing a path to a yml file
49
+ - A Pathname object with a path to a yml file
50
+
51
+ `config.replacement` accepts the following values:
52
+
53
+ - :default : Uses the :garbled method
54
+ - :garbled : Replaces profane words with $@!#%
55
+ - :stars : Replaces profane words with '*' up to the word's length
56
+ - :vowels : Replaces the vowels in the profane word with '*'
57
+ - :nonconsonants : Replaces non consonants with '*'
58
+ - "custom string" : Replaces the profane word with the custom string
59
+
60
+ Example:
61
+
62
+ ```ruby
63
+ Obscenity.configure do |config|
64
+ config.blacklist = "path/to/blacklist/file.yml"
65
+ config.whitelist = ["safe", "word"]
66
+ config.replacement = :stars
67
+ end
68
+ ```
69
+
70
+ ### Basic Usage
71
+
72
+ `Obscenity.profane?(text)` analyses the content and returns `true` or `false` based on its profanity:
73
+
74
+ ```ruby
75
+ Obscenity.profane?("simple text")
76
+ => false
77
+
78
+ Obscenity.profane?("text with shit")
79
+ => true
80
+ ```
81
+
82
+ `Obscenity.sanitize(text)` sanities the content and returns a new sanitized content (if profane) or the original content (if not profane):
83
+
84
+ ```ruby
85
+ Obscenity.sanitize("simple text")
86
+ => "simple text"
87
+
88
+ Obscenity.sanitize("text with shit")
89
+ => "text with $@!#%"
90
+ ```
91
+
92
+ `Obscenity.replacement(style).sanitize(text)` allows you to pass the replacement method to be used when sanitizing the given content. Available replacement values are `:default`, `:garbled`, `:stars`, `:vowels`, and a custom string.
93
+
94
+ ```ruby
95
+ Obscenity.replacement(:default).sanitize("text with shit")
96
+ => "text with $@!#%"
97
+
98
+ Obscenity.replacement(:garbled).sanitize("text with shit")
99
+ => "text with $@!#%"
100
+
101
+ Obscenity.replacement(:stars).sanitize("text with shit")
102
+ => "text with ****"
103
+
104
+ Obscenity.replacement(:vowels).sanitize("text with shit")
105
+ => "text with sh*t"
106
+
107
+ Obscenity.replacement(:nonconsonants).sanitize('Oh 5hit')
108
+ => "Oh *h*t"
109
+
110
+ Obscenity.replacement("[censored]").sanitize("text with shit")
111
+ => "text with [censored]"
112
+ ```
113
+
114
+ `Obscenity.offensive(text)` returns an array of profane words in the given content:
115
+
116
+ ```ruby
117
+ Obscenity.offensive("simple text")
118
+ => []
119
+
120
+ Obscenity.offensive("text with shit and another biatch")
121
+ => ["shit", "biatch"]
122
+ ```
123
+
124
+ ### ActiveModel
125
+
126
+ The ActiveModel component provides easy profanity validation for your models.
127
+
128
+ First, you need to explicitly require the ActiveModel component:
129
+
130
+ ```ruby
131
+ require 'obscenity/active_model'
132
+ ```
133
+
134
+ Then you can use it in your models as such:
135
+
136
+ ```ruby
137
+ # ActiveRecord example
138
+ class Post < ActiveRecord::Base
139
+
140
+ validates :title, obscenity: true
141
+ validates :body, obscenity: { sanitize: true, replacement: "[censored]" }
142
+ end
143
+
144
+ # MongoMapper example
145
+ class Book
146
+ include MongoMapper::Document
147
+
148
+ key :title, String
149
+ key :body, String
150
+
151
+ validates :title, obscenity: true
152
+ validates :body, obscenity: { sanitize: true, replacement: :vowels }
153
+ end
154
+
155
+ # Mongoid example
156
+ class Page
157
+ include Mongoid::Document
158
+
159
+ field :title, type: String
160
+ field :body, type: String
161
+
162
+ validates :title, obscenity: true
163
+ validates :body, obscenity: { sanitize: true, replacement: :garbled }
164
+ end
165
+ ```
166
+
167
+ The following usage is available:
168
+
169
+ `obscenity: true` : Does a profanity validation in the field using `.profane?` and returns `true/false`. If true, ActiveModel's Validation will return a default error message.
170
+
171
+ `obscenity: { message: 'Custom message' }` : Does a profanity validation in the field using `.profane?` and returns `true/false`. If true, ActiveModel's Validation will return your custom error message.
172
+
173
+ `obscenity: { sanitize: true }` : Silently sanitizes the field and replaces its content with the sanitized version. If the `:replacement` key is included, it will use that style when replacing the content.
174
+
175
+ ### Rack middleware
176
+
177
+ You can use Obscenity as a Rack middleware to automatically reject requests that include profane parameter values or sanitize those values before they reach your Application.
178
+
179
+ First you need to explicitly require the Rack middleware:
180
+
181
+ ```ruby
182
+ require 'obscenity/rack'
183
+ ```
184
+
185
+ And to use the middleware, the basic syntax is:
186
+
187
+ ```ruby
188
+ use Rack::Obscenity, {} # options Hash
189
+ ```
190
+
191
+ You need to use the options below inside the options Hash (above)
192
+
193
+ #### Rejecting Requests:
194
+
195
+ Any of the following options can be used to reject a request.
196
+
197
+ `reject: true` : will reject a request if any parameter value contains profanity.
198
+
199
+ ```ruby
200
+ use Rack::Obscenity, reject: true
201
+ ```
202
+
203
+ `reject: { params: [] }` : will analyze the selected parameters and reject the request if their values contain profanity.
204
+
205
+ ```ruby
206
+ use Rack::Obscenity, reject: { params: [:foo, :bar] }
207
+ ```
208
+
209
+ `reject: { message: 'Custom message' }` : will reject a request and display the custom message if any parameter value contains profanity
210
+
211
+ ```ruby
212
+ use Rack::Obscenity, reject: { message: "We don't allow profanity!" }
213
+ ```
214
+
215
+ `reject: { path: 'path/to/file' }` : will reject a request and render the custom file if any parameter value contains profanity
216
+
217
+ ```ruby
218
+ use Rack::Obscenity, reject: { path: 'public/no_profanity.html' }
219
+ ```
220
+
221
+ More usage example:
222
+
223
+ ```ruby
224
+ # Rejects the request for all params and renders a file
225
+ use Rack::Obscenity, reject: { params: :all, path: 'public/no_profanity.html' }
226
+
227
+ # Rejects the request based on the selected params and renders a file
228
+ use Rack::Obscenity, reject: { params: [:foo, :bar], path: 'public/no_profanity.html' }
229
+
230
+ # Rejects the request based on the selected params and displays a message
231
+ use Rack::Obscenity, reject: { params: [:foo, :bar], message: "Profanity is not allowed!" }
232
+ ```
233
+
234
+ #### Sanitizing Requests:
235
+
236
+ Any of the following options can be used to sanitize a request.
237
+
238
+ `sanitize: true` : will sanitize all parameter values if they contain profanity.
239
+
240
+ ```ruby
241
+ use Rack::Obscenity, sanitize: true
242
+ ```
243
+
244
+ `sanitize: { params: [] }` : will analyze the selected parameters and sanitize them if their values contain profanity.
245
+
246
+ ```ruby
247
+ use Rack::Obscenity, sanitize: { params: [:foo, :bar] }
248
+ ```
249
+
250
+ `sanitize: { replacement: (:default | :garbled | :stars | :vowels | 'custom') }` : will use this replacement method when sanitizing parameter values
251
+
252
+ ```ruby
253
+ use Rack::Obscenity, sanitize: { replacement: :vowels }
254
+ ```
255
+
256
+ More usage example:
257
+
258
+ ```ruby
259
+ # Sanitizes all params and replaces their values using :stars
260
+ use Rack::Obscenity, sanitize: { params: :all, replacement: :stars }
261
+
262
+ # Sanitizes the given params and replaces their values using a custom word
263
+ use Rack::Obscenity, sanitize: { params: [:foo, :bar], replacement: "[censored]" }
264
+
265
+ # Sanitizes all params and replaces their values using :garbled
266
+ use Rack::Obscenity, sanitize: { replacement: :garbled }
267
+ ```
268
+ ### Test Helpers
269
+
270
+ Obscenity currently provides test helpers for RSpec only, but we have plans to add helpers to Shoulda as well.
271
+
272
+ #### RSpec Matcher
273
+
274
+ A `be_profane` matcher is available for RSpec. Its usage is very simple:
275
+
276
+ ```ruby
277
+ user.username.should_not be_profane
278
+ ```
279
+
280
+ ## Contributing to obscenity
281
+
282
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
283
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
284
+ * Fork the project.
285
+ * Start a feature/bugfix branch.
286
+ * Commit and push until you are happy with your contribution.
287
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
288
+ * Please try not to mess with the Rakefile, version, or history.
289
+
290
+ ## Authors
291
+
292
+ * Thiago Jackiw: [@tjackiw](http://twitter.com/tjackiw)
293
+
294
+ ## Copyright
295
+
296
+ Copyright (c) 2025 Ropetow. See LICENSE.txt for further details.
297
+