From 9a978e99a4d6e29a80fc391e3f7a781ec002e98d Mon Sep 17 00:00:00 2001 From: Fynn Heintz Date: Mon, 9 May 2022 17:12:03 +0200 Subject: [PATCH] ignore ban-whorty words when they're part of other words --- lib/censor.js | 2 +- test/censor.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/censor.js b/lib/censor.js index ab9e372..41d4992 100644 --- a/lib/censor.js +++ b/lib/censor.js @@ -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) { diff --git a/test/censor.js b/test/censor.js index d6c6c2f..148e756 100644 --- a/test/censor.js +++ b/test/censor.js @@ -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.'),