badwords
badwords copied to clipboard
Don't crash w/strings with no word boundaries
Fixes https://github.com/web-mech/badwords/issues/93
TypeError: Cannot read property '0' of null
can this get merged? it seems like a huge oversight to crash with a wordless string.
Any news on this PR when it can be merged?
Any updates?
I would just like to place another vote to merge this PR. I would love to use this package in production but can't due to this error.
I would just like to place another vote to merge this PR. I would love to use this package in production but can't due to this error.
I yoinked some code from the changes in this pr, but I just overrode the clean method to fit my needs. Kinda a pain in the behind if you have multiple filters but guess this is all we can do unless we want to fork and make our own... or wait.
let customFilter = new Filter({
placeHolder: "*",
});
customFilter.clean = (string) => {
try {
const splitMap = string.split(ProfaneFilter.splitRegex).map((word) => {
return ProfaneFilter.isProfane(word) ? ProfaneFilter.replaceWord(word) : word;
});
if (splitMap.length < 2) return string;
return splitMap.join(ProfaneFilter.splitRegex.exec(string)[0]);
} catch (e) {
return string;
}
};
customFilter.clean("you are a meanie");
Would love this PR to be merged to prevent crashing on strings like :)
or like this ...
import BaseBadWordsFilter from 'bad-words';
class BadWordsFilter extends BaseBadWordsFilter {
private readonly splitRegex!: RegExp;
clean(string: string): string {
try {
const joinMatch = this.splitRegex.exec(string);
const joinString = joinMatch?.[0] || '';
return string
.split(this.splitRegex)
.map(word => {
return this.isProfane(word) ? this.replaceWord(word) : word;
})
.join(joinString);
} catch (e) {
return string;
}
}
}
This really needs to be addressed the Library is poor without it
thanks for the fix