-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't crash w/strings with no word boundaries #95
base: next
Are you sure you want to change the base?
Conversation
"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 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 |
@spravo @IsaiahPapa why is the |
This wrapper will fix most issues listed on the issue tabs. We'll get there :) |
Fixes #93