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
This commit is contained in:
Evan
2026-04-06 14:18:32 -07:00
committed by GitHub
parent 0a117aead3
commit 2f95314dce
2 changed files with 22 additions and 2 deletions
+6 -2
View File
@@ -84,7 +84,9 @@ export function createMatcher(bannedWords: string[]): RegExpMatcher {
});
return {
hasMatch: (input: string) =>
substringMatcher.hasMatch(input) || collapseMatcher.hasMatch(input),
input.toLowerCase().includes("kkk") ||
substringMatcher.hasMatch(input) ||
collapseMatcher.hasMatch(input),
getAllMatches: (input: string, sorted?: boolean) => [
...substringMatcher.getAllMatches(input, sorted),
...collapseMatcher.getAllMatches(input, sorted),
@@ -118,7 +120,9 @@ function censorUsernameWithMatcher(
? username.replace(`[${clanTag}]`, "").trim()
: username;
const clanTagIsProfane = clanTag ? matcher.hasMatch(clanTag) : false;
const clanTagIsProfane = clanTag
? matcher.hasMatch(clanTag) || clanTag.toLowerCase() === "ss"
: false;
const usernameIsProfane = matcher.hasMatch(nameWithoutClan);
const censoredName = usernameIsProfane
+16
View File
@@ -131,6 +131,13 @@ describe("UsernameCensor", () => {
// "snigger" is whitelisted in englishDataset
expect(matcher.hasMatch("snigger")).toBe(false);
});
test("catches kkk as substring", () => {
expect(matcher.hasMatch("kkk")).toBe(true);
expect(matcher.hasMatch("KKK")).toBe(true);
expect(matcher.hasMatch("kkklover")).toBe(true);
expect(matcher.hasMatch("ilovekkkboys")).toBe(true);
});
});
describe("censorUsername", () => {
@@ -186,6 +193,15 @@ describe("UsernameCensor", () => {
expect(checker.censorUsername("[NAZI]CoolPlayer")).toBe("CoolPlayer");
});
test("removes [SS] clan tag", () => {
expect(checker.censorUsername("[SS]Player")).toBe("Player");
expect(checker.censorUsername("[ss]Player")).toBe("Player");
});
test("removes [KKK] clan tag", () => {
expect(checker.censorUsername("[KKK]Player")).toBe("Player");
});
test("keeps clean clan tag when username is clean", () => {
expect(checker.censorUsername("[COOL]Player")).toBe("[COOL] Player");
expect(checker.censorUsername("[PRO]Player")).toBe("[PRO] Player");