From a0f54b30be38bd1e85cf17e496b1bf72e78588e7 Mon Sep 17 00:00:00 2001 From: Eugene Toder Date: Mon, 2 Dec 2024 19:19:32 -0500 Subject: [PATCH] Unban some innocent words --- src/util.js | 24 ++++++++++++++++++------ src/util.test.js | 3 +++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/util.js b/src/util.js index 068a8a1..58781b3 100644 --- a/src/util.js +++ b/src/util.js @@ -1,12 +1,13 @@ import animals from "./utils/animals.json"; import moment from "moment"; import { + DataSet, + pattern, RegExpMatcher, TextCensor, - asteriskCensorStrategy, englishDataset, englishRecommendedTransformers, - keepStartCensorStrategy, + fixedPhraseCensorStrategy, } from "obscenity"; import red from "@material-ui/core/colors/red"; import pink from "@material-ui/core/colors/pink"; @@ -24,13 +25,24 @@ import amber from "@material-ui/core/colors/amber"; import orange from "@material-ui/core/colors/orange"; import deepOrange from "@material-ui/core/colors/deepOrange"; +const fixedDataset = englishDataset + .removePhrasesIf((phrase) => phrase.metadata.originalWord === "dick") + .addPhrase((phrase) => + phrase + .setMetadata({ originalWord: "dick" }) + .addPattern(pattern`dick`) + .addPattern(pattern`|dck|`) + .addWhitelistedTerm("benedick") + .addWhitelistedTerm("dickens") + ) + .addPhrase((phrase) => + phrase.setMetadata({ originalWord: "fuck" }).addWhitelistedTerm("fickle") + ); export const badWords = new RegExpMatcher({ - ...englishDataset.build(), + ...fixedDataset.build(), ...englishRecommendedTransformers, }); -const censor = new TextCensor().setStrategy( - keepStartCensorStrategy(asteriskCensorStrategy()) -); +const censor = new TextCensor().setStrategy(fixedPhraseCensorStrategy("🤬")); export const colors = { red, diff --git a/src/util.test.js b/src/util.test.js index db87b46..9147536 100644 --- a/src/util.test.js +++ b/src/util.test.js @@ -83,5 +83,8 @@ describe("bad words filter", () => { expect(badWords.hasMatch("fuck")).toBe(true); expect(badWords.hasMatch("cunting")).toBe(true); expect(badWords.hasMatch("retard")).toBe(true); + expect(badWords.hasMatch("ducks")).toBe(false); + expect(badWords.hasMatch("deck")).toBe(false); + expect(badWords.hasMatch("fickle")).toBe(false); }); });