badwords icon indicating copy to clipboard operation
badwords copied to clipboard

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

Open gpmcadam opened this issue 4 years ago • 4 comments

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.

gpmcadam avatar Jul 06 '20 14:07 gpmcadam

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

ha6000 avatar Jul 26 '20 10:07 ha6000

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 ]

Jameskmonger avatar Jan 14 '21 18:01 Jameskmonger

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

ha6000 avatar Jan 18 '21 14:01 ha6000

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...

zajako avatar Jul 27 '21 17:07 zajako