badwords
badwords copied to clipboard
Issue with symbols / emoji only strings
When running the clean()
function with a string containing only emojis or symbols I receive the following error:
TypeError: Cannot read property '0' of null
at Filter.clean in bad-words/lib/badwords.js — line 58
As a workaround, I currently add "ABC" at the end of every string and remove it after the cleanup.
Example code:
const ProfanityFilter = require('bad-words');
const profanityFilter = new ProfanityFilter();
profanityFilter.clean('🙂');
profanityFilter.clean('.,-*');
Getting the same problem. Will try the workaround by @lkgoerges
For those interested, I'm using this as a workaround for now.
// filename bad-words-hacked.js
const Filter = require('bad-words')
class FilterHacked extends Filter {
cleanHacked(string) {
try {
return this.clean(string);
} catch {
const joinMatch = this.splitRegex.exec(string);
const joinString = (joinMatch && joinMatch[0]) || '';
return string.split(this.splitRegex).map((word) => {
return this.isProfane(word) ? this.replaceWord(word) : word;
}).join(joinString);
}
}
}
module.exports = FilterHacked
Example code:
var Filter = require('./bad-words-hacked');
filter = new Filter();
const filteredString = filter.cleanHacked(string);
Looks like this repo is pretty much abandoned. Does anyone have a fork they plan on maintaining?