From c7ed42148ca0bad94e777ffe3bb0f5d3d5953ca3 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Tue, 26 Nov 2024 22:14:43 +0200 Subject: [PATCH] Disallow empty custom user names --- app/constants.ts | 6 ++++++ app/features/user-page/routes/u.$identifier.edit.tsx | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/constants.ts b/app/constants.ts index 00a80496c..f27d3b3fc 100644 --- a/app/constants.ts +++ b/app/constants.ts @@ -3,10 +3,16 @@ import type { BuildAbilitiesTupleWithUnknown } from "./modules/in-game-lists"; export const TWEET_LENGTH_MAX_LENGTH = 280; export const DISCORD_MESSAGE_MAX_LENGTH = 2000; +const EMPTY_CHARACTERS = ["\u200B", "\u200C", "\u200D", "\u200E", "\u200F"]; +export const notAllEmptyCharactersRegExp = new RegExp( + `^(?!(${EMPTY_CHARACTERS.join("|")})+$).*$`, +); + export const USER = { BIO_MAX_LENGTH: DISCORD_MESSAGE_MAX_LENGTH, CUSTOM_URL_MAX_LENGTH: 32, CUSTOM_NAME_MAX_LENGTH: 32, + CUSTOM_NAME_REGEXP: notAllEmptyCharactersRegExp, BATTLEFY_MAX_LENGTH: 32, BSKY_MAX_LENGTH: 50, IN_GAME_NAME_TEXT_MAX_LENGTH: 20, diff --git a/app/features/user-page/routes/u.$identifier.edit.tsx b/app/features/user-page/routes/u.$identifier.edit.tsx index e85d9aecc..f943e61d7 100644 --- a/app/features/user-page/routes/u.$identifier.edit.tsx +++ b/app/features/user-page/routes/u.$identifier.edit.tsx @@ -88,7 +88,12 @@ const userEditActionSchema = z ), customName: z.preprocess( falsyToNull, - z.string().trim().max(USER.CUSTOM_NAME_MAX_LENGTH).nullable(), + z + .string() + .trim() + .regex(USER.CUSTOM_NAME_REGEXP) + .max(USER.CUSTOM_NAME_MAX_LENGTH) + .nullable(), ), battlefy: z.preprocess( falsyToNull,