Skip to content

Commit 2f95314

Browse files
authored
Update name censor to check for certain substrings (#3603)
## Description: The deduper was converting profane words like "kkk" => "k" and then censoring all usernames with the letter "k", so instead we just hardcode and check for substrings for profane phrases like that. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
1 parent 0a117ae commit 2f95314

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/server/Privilege.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export function createMatcher(bannedWords: string[]): RegExpMatcher {
8484
});
8585
return {
8686
hasMatch: (input: string) =>
87-
substringMatcher.hasMatch(input) || collapseMatcher.hasMatch(input),
87+
input.toLowerCase().includes("kkk") ||
88+
substringMatcher.hasMatch(input) ||
89+
collapseMatcher.hasMatch(input),
8890
getAllMatches: (input: string, sorted?: boolean) => [
8991
...substringMatcher.getAllMatches(input, sorted),
9092
...collapseMatcher.getAllMatches(input, sorted),
@@ -118,7 +120,9 @@ function censorUsernameWithMatcher(
118120
? username.replace(`[${clanTag}]`, "").trim()
119121
: username;
120122

121-
const clanTagIsProfane = clanTag ? matcher.hasMatch(clanTag) : false;
123+
const clanTagIsProfane = clanTag
124+
? matcher.hasMatch(clanTag) || clanTag.toLowerCase() === "ss"
125+
: false;
122126
const usernameIsProfane = matcher.hasMatch(nameWithoutClan);
123127

124128
const censoredName = usernameIsProfane

tests/Privilege.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ describe("UsernameCensor", () => {
131131
// "snigger" is whitelisted in englishDataset
132132
expect(matcher.hasMatch("snigger")).toBe(false);
133133
});
134+
135+
test("catches kkk as substring", () => {
136+
expect(matcher.hasMatch("kkk")).toBe(true);
137+
expect(matcher.hasMatch("KKK")).toBe(true);
138+
expect(matcher.hasMatch("kkklover")).toBe(true);
139+
expect(matcher.hasMatch("ilovekkkboys")).toBe(true);
140+
});
134141
});
135142

136143
describe("censorUsername", () => {
@@ -186,6 +193,15 @@ describe("UsernameCensor", () => {
186193
expect(checker.censorUsername("[NAZI]CoolPlayer")).toBe("CoolPlayer");
187194
});
188195

196+
test("removes [SS] clan tag", () => {
197+
expect(checker.censorUsername("[SS]Player")).toBe("Player");
198+
expect(checker.censorUsername("[ss]Player")).toBe("Player");
199+
});
200+
201+
test("removes [KKK] clan tag", () => {
202+
expect(checker.censorUsername("[KKK]Player")).toBe("Player");
203+
});
204+
189205
test("keeps clean clan tag when username is clean", () => {
190206
expect(checker.censorUsername("[COOL]Player")).toBe("[COOL] Player");
191207
expect(checker.censorUsername("[PRO]Player")).toBe("[PRO] Player");

0 commit comments

Comments
 (0)