Skip to content

Commit

Permalink
fix(*): update removeWords functionality to be case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
web-mech committed Feb 19, 2019
1 parent b398740 commit 235121d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/badwords.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Filter {
return this.list
.filter((word) => {
const wordExp = new RegExp(`\\b${word.replace(/(\W)/g, '\\$1')}\\b`, 'gi');
return !this.exclude.includes(word) && wordExp.test(string);
return !this.exclude.includes(word.toLowerCase()) && wordExp.test(string);
})
.length > 0 || false;
}
Expand Down Expand Up @@ -65,19 +65,21 @@ class Filter {

this.list.push(...words);

words.forEach((word) => {
if (this.exclude.includes(word)) {
this.exclude.splice(this.exclude.indexOf(word), 1);
}
});
words
.map(word => word.toLowerCase())
.forEach((word) => {
if (this.exclude.includes(word)) {
this.exclude.splice(this.exclude.indexOf(word), 1);
}
});
}

/**
* Add words to whitelist filter
* @param {...string} word - Word(s) to add to whitelist.
*/
removeWords() {
this.exclude.push(...Array.from(arguments));
this.exclude.push(...Array.from(arguments).map(word => word.toLowerCase()));
}
}

Expand Down

0 comments on commit 235121d

Please sign in to comment.