From 1bb9d32ea06af8777e3f27438ad81b0a72905821 Mon Sep 17 00:00:00 2001 From: UGilfoyle Date: Sat, 22 Aug 2026 14:40:28 +0530 Subject: [PATCH] fix: allow apostrophes in validatePersonName and unit tests --- packages/utils/package.json | 4 +- packages/utils/src/validation.ts | 10 +- packages/utils/tests/validation.test.ts | 151 ++++++++++++++++++++++++ pnpm-lock.yaml | 4 + 4 files changed, 164 insertions(+), 5 deletions(-) create mode 100644 packages/utils/tests/validation.test.ts diff --git a/packages/utils/package.json b/packages/utils/package.json index 2dc85cda7fb..286ec8ced7b 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -15,6 +15,7 @@ "scripts": { "build": "tsdown", "dev": "tsdown --watch --no-clean", + "test": "vitest run", "check:lint": "oxlint --max-warnings=38 .", "check:types": "tsc --noEmit", "check:format": "oxfmt --check .", @@ -53,6 +54,7 @@ "@types/react": "catalog:", "@types/sanitize-html": "catalog:", "tsdown": "catalog:", - "typescript": "catalog:" + "typescript": "catalog:", + "vitest": "catalog:" } } diff --git a/packages/utils/src/validation.ts b/packages/utils/src/validation.ts index 2b61a4a54d5..d9ab493dcb2 100644 --- a/packages/utils/src/validation.ts +++ b/packages/utils/src/validation.ts @@ -78,8 +78,8 @@ export const validatePersonName = (name: string): boolean | string => { return "Name must be 50 characters or less"; } - if (hasInjectionRiskChars(name)) { - return "Names cannot contain special characters like < > ' \" { } [ ] * ^ ! # %"; + if (hasInjectionRiskChars(name, { allowApostrophe: true })) { + return 'Names cannot contain special characters like < > " { } [ ] * ^ ! # %'; } if (!PERSON_NAME_REGEX.test(name)) { @@ -219,12 +219,14 @@ export const validateSlug = (slug: string): boolean | string => { /** * @description Checks if a string contains any injection-risk characters * @param {string} input - String to check + * @param {boolean} [options.allowApostrophe=false] - Whether to allow apostrophes (e.g. for person names) * @returns {boolean} true if injection-risk characters found * @example * hasInjectionRiskChars("Hello World") // returns false * hasInjectionRiskChars("Hello