Disallow empty custom user names

This commit is contained in:
Kalle
2024-11-26 22:14:43 +02:00
parent 41ae9969b6
commit c7ed42148c
2 changed files with 12 additions and 1 deletions

View File

@@ -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,

View File

@@ -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,