diff --git a/__tests__/common/object.ts b/__tests__/common/object.ts new file mode 100644 index 0000000000..f05800280a --- /dev/null +++ b/__tests__/common/object.ts @@ -0,0 +1,32 @@ +import { socialHandleRegex, handleRegex } from '../../src/common/object'; + +describe('Unicode regex patterns', () => { + it('socialHandleRegex supports Unicode with optional @ prefix', () => { + // Valid Unicode handles + expect(socialHandleRegex.test('@José')).toBe(true); + expect(socialHandleRegex.test('François-dev')).toBe(true); + expect(socialHandleRegex.test('北京')).toBe(true); + expect(socialHandleRegex.test('user_123')).toBe(true); + expect(socialHandleRegex.test('@' + 'a'.repeat(39))).toBe(true); + + // Invalid handles + expect(socialHandleRegex.test('')).toBe(false); + expect(socialHandleRegex.test('a'.repeat(40))).toBe(false); + expect(socialHandleRegex.test('has space')).toBe(false); + expect(socialHandleRegex.test('bad!char')).toBe(false); + }); + + it('handleRegex supports Unicode without hyphens', () => { + // Valid handles (3-39 chars, no hyphens) + expect(handleRegex.test('abc')).toBe(true); + expect(handleRegex.test('@user_name')).toBe(true); + expect(handleRegex.test('Jöhn123')).toBe(true); + expect(handleRegex.test('@' + 'a'.repeat(39))).toBe(true); + + // Invalid handles + expect(handleRegex.test('ab')).toBe(false); // too short + expect(handleRegex.test('François-dev')).toBe(false); // has hyphen + expect(handleRegex.test('bad handle')).toBe(false); // has space + expect(handleRegex.test('a'.repeat(40))).toBe(false); // too long + }); +}); diff --git a/src/common/object.ts b/src/common/object.ts index d99c685bab..9d1ad65009 100644 --- a/src/common/object.ts +++ b/src/common/object.ts @@ -51,10 +51,11 @@ export const validateRegex = ( return mutatedData as T; }; - export const nameRegex = new RegExp(/^(.){1,60}$/); -export const socialHandleRegex = new RegExp(/^@?([\w-]){1,39}$/i); -export const handleRegex = new RegExp(/^@?[a-z0-9](\w){2,38}$/i); +// Updated to support Unicode word characters (including accented characters) +export const socialHandleRegex = new RegExp(/^@?([\p{L}\p{N}_-]){1,39}$/iu); +// Updated to support Unicode word characters (including accented characters) +export const handleRegex = new RegExp(/^@?[\p{L}\p{N}]([\p{L}\p{N}_]){2,38}$/iu); export const descriptionRegex = new RegExp(/^[\S\s]{1,250}$/); // Originated from: https://github.com/colinhacks/zod/blob/8552233c77426f77d3586cc877f7aec1aa0aa45b/src/types.ts#L599-L600 export const emailRegex = new RegExp(