-
Notifications
You must be signed in to change notification settings - Fork 99
Can't reconfigure after first blacklist configuration #8
Comments
I figured out a way to work around this. The solution is don't use I haven't tested this, but a better fix might be to change this method in the Config class: def blacklist=(value)
@blacklist = value == :default ? DEFAULT_BLACKLIST : value
end ...to this... def blacklist=(value)
Obscenity::Base.blacklist = @blacklist = value == :default ? DEFAULT_BLACKLIST : value
end |
What about keeping the issue open, @chrisvfritz? It is reasonable to expect your earlier code to work... |
Yes, please keep the issue open. Thanks.
|
This goes beyond the scope of the bug, but my preferred solution would involve the creation of Obscenity instances, each of which would have their own configuration, and to do away with the config class altogether. So for example, I could do: sex_filter = Obscenity.new(blacklist: ['sexual','language'], replacement: :stars)
# then should I want to later modify the sex_filter, I could simply use...
sex_filter.blacklist = ['different','words']
sex_filter.whitelist = ['please','thank you']
sex_filter.replacement = :vowels
# and using the filter on text would work very much the same
sex_filter.profane? "here's some text to check against the blacklist"
sex_filter.sanitize "some more text" That makes more intuitive sense to me, but maybe this gem is simply focused on a different set of needs. This change would involve a pretty substantial rewrite and I could give it a shot, but I'm not sure if it would be an appropriate pull request, as it would break the gem for others using it. Thoughts? |
OK - I ended up just writing a new language_filter gem that did everything I needed it to, as I needed one relatively urgently for work. The development was too rushed to be test-driven unfortunately, so tests will be coming soon. But here are some advantages over the Obscenity gem:
I'd love to hear what others think and to get contributions to make it better. There's plenty of room for improvement of the matchlists - and for more matchlist categories to be added. And there still may be a bug or two lurking around. And of course, if anyone wanted to write the tests while I'm away for the fourth, I would welcome the pull request. :-) |
Any feedback on whether this or the other PR's are going to be merged? Ran into same issue. Thanks! |
If I try to reconfigure obscenity to switch between multiple blacklists, it'll claim to be pointing to the new list, without actually using it in
sanitize
. For example, in this code:Whichever filter I call first sets the list that all other filters will use until I restart my Rails app, even though I'm telling it to point to another list. If I call
Obscenity.config.blacklist
, it'll even report to be pointing to the correct list.The text was updated successfully, but these errors were encountered: