web-mech / badwords

A javascript filter for badwords
MIT License
621 stars 325 forks source link

Bug: won't find word with dash/hyphen profane #82

Open gpmcadam opened 4 years ago

gpmcadam commented 4 years ago

Given the example below:

const BadWords = require('bad-words');
const bw = new BadWords()
bw.addWords(['foo-bar', 'foobar'])

> bw.isProfane('foobar')
'foobar'

> bw.isProfane('foo-bar')
false

I would expect bw.isProfine('foo-bar') to return "foo-bar" and not false.

ha6000 commented 4 years ago

I am pretty sure you add words in arguments and not array, like bw.addWords('foo-bar', 'foobar') and when I did that both returned true, which from documentation is the expected result

Jameskmonger commented 3 years ago

The same happens with underscores

const filter = new Filter({ list: ['some', 'bad', 'word'] }); 

[
    filter.isProfane("some bad word"),
    filter.isProfane("some_bad_word")   
]
// [ true, false ]
ha6000 commented 3 years ago

The library is only meant to check between word boundaries, so I would not say it is a bug.

zajako commented 3 years ago

Then maybe this should be a feature request... its also a problem with words merged together with no boundary.

const filter = new Filter({ list: ['some', 'bad', 'word'] }); [ filter.isProfane("some bad word"), filter.isProfane("somebadword")
] // [ true, false ]

When really offensive words are used like this, it doesn't matter if there are spaces, its still offensive and should be considered profane...