From e32e9948f9a241619cdb487cb97dd9eb2881bdaa Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Sat, 4 Apr 2026 10:49:58 +0300 Subject: [PATCH 1/2] Change error message --- .../__tests__/api/controllers/user.spec.ts | 22 +++++++++--------- .../__test__/validation/validation.spec.ts | 6 +++-- packages/schemas/src/users.ts | 6 ++--- packages/schemas/src/validation/validation.ts | 23 +++++++++---------- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/backend/__tests__/api/controllers/user.spec.ts b/backend/__tests__/api/controllers/user.spec.ts index 0a20e957523f..ab25ef2eceea 100644 --- a/backend/__tests__/api/controllers/user.spec.ts +++ b/backend/__tests__/api/controllers/user.spec.ts @@ -193,7 +193,7 @@ describe("user controller test", () => { ], }); }); - it("should fail if username contains profanity", async () => { + it("should fail if username contains bad word", async () => { //GIVEN const newUser = { uid: uid, @@ -212,7 +212,7 @@ describe("user controller test", () => { expect(body).toEqual({ message: "Invalid request data schema", validationErrors: [ - '"name" Profanity detected. Please remove it. If you believe this is a mistake, please contact us. (miodec)', + '"name" Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (miodec).', ], }); }); @@ -277,7 +277,7 @@ describe("user controller test", () => { }); expect(userIsNameAvailableMock).toHaveBeenCalledWith("bob", uid); }); - it("returns 422 if username contains profanity", async () => { + it("returns 422 if username contains bad word", async () => { await mockApp .get("/users/checkName/newMiodec") //no authentication required @@ -1139,7 +1139,7 @@ describe("user controller test", () => { validationErrors: ["Unrecognized key(s) in object: 'extra'"], }); }); - it("should fail if username contains profanity", async () => { + it("should fail if username contains bad word", async () => { //WHEN const { body } = await mockApp .patch("/users/name") @@ -1151,7 +1151,7 @@ describe("user controller test", () => { expect(body).toEqual({ message: "Invalid request data schema", validationErrors: [ - '"name" Profanity detected. Please remove it. If you believe this is a mistake, please contact us. (miodec)', + '"name" Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (miodec).', ], }); }); @@ -3310,7 +3310,7 @@ describe("user controller test", () => { expect.objectContaining({}), ); }); - it("should fail with profanity", async () => { + it("should fail with bad word", async () => { //WHEN const { body } = await mockApp .patch("/users/profile") @@ -3330,11 +3330,11 @@ describe("user controller test", () => { expect(body).toEqual({ message: "Invalid request data schema", validationErrors: [ - '"bio" Profanity detected. Please remove it. If you believe this is a mistake, please contact us. (miodec)', - '"keyboard" Profanity detected. Please remove it. If you believe this is a mistake, please contact us. (miodec)', - '"socialProfiles.twitter" Profanity detected. Please remove it. If you believe this is a mistake, please contact us. (miodec)', - '"socialProfiles.github" Profanity detected. Please remove it. If you believe this is a mistake, please contact us. (miodec)', - '"socialProfiles.website" Profanity detected. Please remove it. If you believe this is a mistake, please contact us. (https://i-luv-miodec.com)', + '"bio" Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (miodec).', + '"keyboard" Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (miodec).', + '"socialProfiles.twitter" Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (miodec).', + '"socialProfiles.github" Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (miodec).', + '"socialProfiles.website" Unallowed detected. Please remove it. If you believe this is a mistake, please contact us (https://i-luv-miodec.com).', ], }); }); diff --git a/packages/contracts/__test__/validation/validation.spec.ts b/packages/contracts/__test__/validation/validation.spec.ts index 4af8689fc913..203b376f36a1 100644 --- a/packages/contracts/__test__/validation/validation.spec.ts +++ b/packages/contracts/__test__/validation/validation.spec.ts @@ -1,8 +1,10 @@ import { describe, it, expect } from "vitest"; import * as Validation from "@monkeytype/schemas/validation/validation"; +const containsBadWords = Validation.__testing.containsBadWords; + describe("validation", () => { - it("containsProfanity", () => { + it("containsBadWords", () => { const testCases = [ { text: "https://www.fuckyou.com", @@ -35,7 +37,7 @@ describe("validation", () => { ]; testCases.forEach((testCase) => { - expect(Validation.containsProfanity(testCase.text, "substring")).toBe( + expect(containsBadWords(testCase.text, "substring")).toBe( testCase.expected, ); }); diff --git a/packages/schemas/src/users.ts b/packages/schemas/src/users.ts index e592c1bea026..f3f8a68f431c 100644 --- a/packages/schemas/src/users.ts +++ b/packages/schemas/src/users.ts @@ -12,7 +12,7 @@ import { PersonalBestSchema, } from "./shared"; import { CustomThemeColorsSchema, FunboxNameSchema } from "./configs"; -import { doesNotContainProfanity } from "./validation/validation"; +import { doesNotContainBadWords } from "./validation/validation"; import { ConnectionSchema } from "./connections"; const NoneFilterSchema = z.literal("none"); @@ -85,7 +85,7 @@ export type UserTag = z.infer; function profileDetailsBase( schema: ZodString, ): ZodEffects>> { - return doesNotContainProfanity("word", schema) + return doesNotContainBadWords("word", schema) .optional() .transform((value) => (value === null ? undefined : value)); } @@ -242,7 +242,7 @@ export const FavoriteQuotesSchema = z.record( export type FavoriteQuotes = z.infer; export const UserEmailSchema = z.string().email(); -export const UserNameSchema = doesNotContainProfanity( +export const UserNameSchema = doesNotContainBadWords( "substring", z .string() diff --git a/packages/schemas/src/validation/validation.ts b/packages/schemas/src/validation/validation.ts index 9ceb06fb1b4c..41e840b21d20 100644 --- a/packages/schemas/src/validation/validation.ts +++ b/packages/schemas/src/validation/validation.ts @@ -2,7 +2,7 @@ import { replaceHomoglyphs } from "./homoglyphs"; import { ZodEffects, ZodString } from "zod"; // Sorry for the bad words -const profanities = [ +const badWords = [ "miodec", "bitly", "niqqa", @@ -403,10 +403,7 @@ function sanitizeString(str: string | undefined): string | undefined { .replace(/\s{3,}/g, " "); } -export function containsProfanity( - text: string, - mode: "word" | "substring", -): boolean { +function containsBadWords(text: string, mode: "word" | "substring"): boolean { const normalizedText = text .toLowerCase() .split(/[.,"/#!?$%^&*;:{}=\-_`~()\s\n]+/g) @@ -414,27 +411,29 @@ export function containsProfanity( return replaceHomoglyphs(sanitizeString(str) ?? ""); }); - const hasProfanity = profanities.some((profanity) => { + const hasBadWords = badWords.some((badWord) => { return normalizedText.some((word) => { return mode === "word" - ? word.startsWith(profanity) - : word.includes(profanity); + ? word.startsWith(badWord) + : word.includes(badWord); }); }); - return hasProfanity; + return hasBadWords; } -export function doesNotContainProfanity( +export function doesNotContainBadWords( mode: "word" | "substring", schema: ZodString, ): ZodEffects { return schema.refine( (val) => { - return !containsProfanity(val, mode); + return !containsBadWords(val, mode); }, (val) => ({ - message: `Profanity detected. Please remove it. If you believe this is a mistake, please contact us. (${val})`, + message: `Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (${val}).`, }), ); } + +export const __testing = { containsBadWords }; From b97a18334163b7dd84833766411b643c69e56722 Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Sat, 4 Apr 2026 10:54:01 +0300 Subject: [PATCH 2/2] Test --- backend/__tests__/api/controllers/user.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/__tests__/api/controllers/user.spec.ts b/backend/__tests__/api/controllers/user.spec.ts index ab25ef2eceea..84be2a9699a0 100644 --- a/backend/__tests__/api/controllers/user.spec.ts +++ b/backend/__tests__/api/controllers/user.spec.ts @@ -3334,7 +3334,7 @@ describe("user controller test", () => { '"keyboard" Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (miodec).', '"socialProfiles.twitter" Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (miodec).', '"socialProfiles.github" Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (miodec).', - '"socialProfiles.website" Unallowed detected. Please remove it. If you believe this is a mistake, please contact us (https://i-luv-miodec.com).', + '"socialProfiles.website" Unallowed word detected. Please remove it. If you believe this is a mistake, please contact us (https://i-luv-miodec.com).', ], }); });