From d6dce787c0084a2702243260437094da596d37e9 Mon Sep 17 00:00:00 2001 From: RealJosephStalin Date: Wed, 12 Feb 2025 02:55:12 -0500 Subject: [PATCH] allow emojis in safestring --- src/core/Schemas.ts | 5 ++++- src/core/validations/username.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/Schemas.ts b/src/core/Schemas.ts index a4b31c18f..9bfae45f5 100644 --- a/src/core/Schemas.ts +++ b/src/core/Schemas.ts @@ -100,7 +100,8 @@ const GameConfigSchema = z.object({ const SafeString = z .string() // Remove common dangerous characters and patterns - .regex(/^[a-zA-Z0-9\s.,!?@#$%&*()-_+=\[\]{}|;:"'\/]+$/) + // The weird \u stuff is to allow emojis + .regex(/^[a-zA-Z0-9\s.,!?@#$%&*()-_+=\[\]{}|;:"'\/\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]]+$/) // Reasonable max length to prevent DOS .max(1000); @@ -323,3 +324,5 @@ export const GameRecordSchema = z.object({ turns: z.array(TurnSchema), winner: ID.nullable(), }); + + diff --git a/src/core/validations/username.ts b/src/core/validations/username.ts index 88a2c1011..c1de0c357 100644 --- a/src/core/validations/username.ts +++ b/src/core/validations/username.ts @@ -13,7 +13,7 @@ const matcher = new RegExpMatcher({ export const MIN_USERNAME_LENGTH = 3; export const MAX_USERNAME_LENGTH = 27; -const validPattern = /^[a-zA-Z0-9_\[\] 🐈🍀]+$/; +const validPattern = /^[a-zA-Z0-9_\[\] 🐈🍀]+$/u; const shadowNames = [ "NicePeopleOnly", @@ -71,7 +71,7 @@ export function validateUsername(username: string): { export function sanitizeUsername(str: string): string { const sanitized = str - .replace(/[^a-zA-Z0-9_\[\] 🐈🍀]/g, "") + .replace(/[^a-zA-Z0-9_\[\] 🐈🍀]/gu, "") .slice(0, MAX_USERNAME_LENGTH); return sanitized.padEnd(MIN_USERNAME_LENGTH, "x"); }