Skip to content

Commit 998b557

Browse files
authored
Replace bad-words with obscenity (#21)
Fixes #12
1 parent b322fd8 commit 998b557

File tree

6 files changed

+34
-42
lines changed

6 files changed

+34
-42
lines changed

package-lock.json

Lines changed: 10 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"@material-ui/icons": "^4.11.2",
1212
"@react-spring/web": "^9.4.4",
1313
"@stripe/stripe-js": "^1.25.0",
14-
"bad-words": "^3.0.4",
1514
"chart.js": "^3.7.1",
1615
"clone-deep": "^4.0.1",
1716
"clsx": "^1.1.1",
1817
"firebase": "^9.6.9",
1918
"moment": "^2.29.1",
19+
"obscenity": "^0.4.0",
2020
"project-name-generator": "^2.1.9",
2121
"react": "^17.0.2",
2222
"react-chartjs-2": "^4.0.1",

src/components/Chat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Scrollbox from "./Scrollbox";
1515
import ChatCards from "./ChatCards";
1616
import ElapsedTime from "./ElapsedTime";
1717
import firebase from "../firebase";
18-
import { filter } from "../util";
18+
import { badWords } from "../util";
1919
import autoscroll from "../utils/autoscroll";
2020
import useFirebaseQuery from "../hooks/useFirebaseQuery";
2121
import useMoment from "../hooks/useMoment";
@@ -97,7 +97,7 @@ function Chat({
9797
function handleSubmit(event) {
9898
event.preventDefault();
9999
if (input) {
100-
if (filter.isProfane(input)) {
100+
if (badWords.hasMatch(input)) {
101101
alert(
102102
"We detected that your message contains profane language. If you think this was a mistake, please let us know!"
103103
);

src/components/PromptDialog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import DialogContent from "@material-ui/core/DialogContent";
88
import DialogContentText from "@material-ui/core/DialogContentText";
99
import DialogTitle from "@material-ui/core/DialogTitle";
1010

11-
import { filter } from "../util";
11+
import { badWords } from "../util";
1212
import { UserContext } from "../context";
1313

1414
function PromptDialog(props) {
@@ -22,7 +22,7 @@ function PromptDialog(props) {
2222
}
2323

2424
function handleSubmit() {
25-
if (filter.isProfane(value)) {
25+
if (badWords.hasMatch(value)) {
2626
alert(
2727
"We detected that your input contains profane language. If you think this was a mistake, please let us know!"
2828
);

src/util.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import animals from "./utils/animals.json";
22
import moment from "moment";
3-
import Filter from "bad-words";
3+
import {
4+
RegExpMatcher,
5+
englishDataset,
6+
englishRecommendedTransformers,
7+
} from "obscenity";
48
import red from "@material-ui/core/colors/red";
59
import pink from "@material-ui/core/colors/pink";
610
import purple from "@material-ui/core/colors/purple";
@@ -17,18 +21,10 @@ import amber from "@material-ui/core/colors/amber";
1721
import orange from "@material-ui/core/colors/orange";
1822
import deepOrange from "@material-ui/core/colors/deepOrange";
1923

20-
export const filter = new Filter();
21-
22-
filter.addWords("cunting");
23-
24-
// See: https://github.com/ekzhang/setwithfriends/issues/117
25-
filter.addWords("retard", "retarded");
26-
27-
// See: https://github.com/ekzhang/setwithfriends/issues/49
28-
filter.removeWords("queer", "queers", "queerz", "qweers", "qweerz", "lesbian");
29-
30-
// See: https://github.com/ekzhang/setwithfriends/issues/71
31-
filter.removeWords("wang");
24+
export const badWords = new RegExpMatcher({
25+
...englishDataset.build(),
26+
...englishRecommendedTransformers,
27+
});
3228

3329
export const colors = {
3430
red,

src/util.test.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
checkSet,
44
checkSetUltra,
55
findSet,
6-
filter,
6+
badWords,
77
} from "./util";
88

99
it("computes conjugate cards", () => {
@@ -74,9 +74,14 @@ describe("findSet()", () => {
7474
});
7575
});
7676

77-
describe("bad-words filter", () => {
78-
it("does not trigger on 'wang'", () => {
79-
expect(filter.isProfane("Rona Wang")).toBe(false);
80-
expect(filter.isProfane("wang")).toBe(false);
77+
describe("bad words filter", () => {
78+
it("sort of works", () => {
79+
expect(badWords.hasMatch("Rona Wang")).toBe(false);
80+
expect(badWords.hasMatch("queer")).toBe(false);
81+
expect(badWords.hasMatch("lesbian")).toBe(false);
82+
expect(badWords.hasMatch("gay")).toBe(false);
83+
expect(badWords.hasMatch("fuck")).toBe(true);
84+
expect(badWords.hasMatch("cunting")).toBe(true);
85+
expect(badWords.hasMatch("retard")).toBe(true);
8186
});
8287
});

0 commit comments

Comments
 (0)