badwords icon indicating copy to clipboard operation
badwords copied to clipboard

No Substring Filter?

Open RADesai opened this issue 4 years ago • 12 comments

Hopefully I'm missing something or using the package incorrectly but seems like its not finding bad words as substrings..?

import Filter from 'bad-words';

const filter = new Filter();

console.log(filter.clean('xyz ass4ca')); // xyz ass4ca
console.log(filter.clean('xyz 555ass')); // xyz 555ass
console.log(filter.clean('xyz ass'));    // xyz ***

RADesai avatar Dec 24 '20 18:12 RADesai

Did you find a solution or another library that does this?

daniandl avatar Jan 10 '21 15:01 daniandl

Bass. Assistant. Raccoon. Shitake mushrooms. Peacock.
B***. ***istant. Rac****. ****ake mushrooms. Pea****.

Is this really a good idea?

brianreavis avatar Jan 29 '21 19:01 brianreavis

It would be nice to at least have the option, as certain racial slurs do not really fit into any other words like Shitake :)

daniandl avatar Jan 29 '21 20:01 daniandl

people bypass the filter by doing adding an underscore on the word, or adding an extra r on the n word

ass_

dolanmiu avatar Mar 09 '21 22:03 dolanmiu

+1 for adding the option to filter substrings. I'm creating a referral code generator that spits out a random alphanumeric code that the user can send to a friend to get them to sign up. We want to reduce the chances of offensive words sneaking into the randomly-generated string.

djflorio avatar Mar 13 '21 14:03 djflorio

I'd love it if there was a way to force certain bad words from being filtered out, like the F word... how many times does the F word show up inside of other words?

Warning, the following contains language that may be found as offensive!

image

All of the above totally bypassed the isProfane function.

dodocodes avatar Mar 22 '21 06:03 dodocodes

@dodocodes is correct in this regard, however, @brianreavis brings up https://www.wikiwand.com/en/Scunthorpe_problem There should be a way to enhance accuracy, e.g. detecting compound curses and ignoring special character padding.

BradKML avatar Mar 22 '21 08:03 BradKML

Bass. Assistant. Raccoon. Shitake mushrooms. Peacock.
B***. ***istant. Rac****. ****ake mushrooms. Pea****.

Is this really a good idea?

Fair point but for some use cases it can be desired, for example when we are generating random character serial numbers for item labels, we would like to filter any expletives that can be accidentally generated as as substring

RADesai avatar Apr 15 '21 04:04 RADesai

Has anyone found a way to enable a substring filter? As mentioned above it is very useful in some use cases.

raymolla7 avatar Sep 27 '21 17:09 raymolla7

Bass. Assistant. Raccoon. Shitake mushrooms. Peacock.
B***. ***istant. Rac****. ****ake mushrooms. Pea****.

Is this really a good idea?

Fair point but for some use cases it can be desired, for example when we are generating random character serial numbers for item labels, we would like to filter any expletives that can be accidentally generated as as substring

I agree that having the option to apply the filter for words containing bad words is desirable. The exclude list should be used to allow words like "raccoon" and "peacock" to pass without issue. Since developers can manage that list using the "removeWords" feature, it should be fairly straight-forward to implement this option without breaking changes.

ktmeagher avatar Sep 29 '21 17:09 ktmeagher

people bypass the filter by doing adding an underscore on the word, or adding an extra r on the n word

ass_

use the following splitRegex to consider _ as a word boundary: new Filter({splitRegex: /(?:(?=[a-zA-Z0-9]))(?<![a-zA-Z0-9])|(?<=[a-zA-Z0-9])(?![a-zA-Z0-9])/})

pankaj9296 avatar Mar 03 '23 10:03 pankaj9296

A slight thought: compound word bounds are good grounds for filtering, inherent words with coincidental substring is not. Problem: how do toy know it is not a prefix or suffix? the "B" in Bass is not a word. The "istant" in Assistant is not a word. The "Rac" in Raccoon is not a word. The "ake" in Shitake is not a word... BUT "Pea" is a word in Peacock. This is can be captured in secondary sense through wordlists.

BradKML avatar Mar 10 '23 09:03 BradKML