Skip to content

Commit

Permalink
ignore ban-whorty words when they're part of other words
Browse files Browse the repository at this point in the history
  • Loading branch information
malfynnction committed May 9, 2022
1 parent dca92c8 commit 9a978e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/censor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = (text) => {
let isCensored = false

censoredPhrases.forEach((phrase) => {
const regex = new RegExp(phrase, 'g')
const regex = new RegExp(`\\b${phrase}\\b`, 'g')
const censoredVersion = phrase.replace(/a|e|i|o|u/, '*')

if (!isCensored) {
Expand Down
4 changes: 4 additions & 0 deletions test/censor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ test("it returns the original text when there's nothing to censor", (t) => {
)
})

test("it ignores the word when it's part of another word", (t) => {
t.is(censor('Medieval'), 'Medieval')
})

test('it replaces slurs & other ban-worthy words with a censored version', (t) => {
t.is(
censor('This is kill a normal sentence, nothing die to see kill here.'),
Expand Down

0 comments on commit 9a978e9

Please sign in to comment.