Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions __tests__/common/object.ts
Original file line number Diff line number Diff line change
@@ -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
});
});
7 changes: 4 additions & 3 deletions src/common/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ export const validateRegex = <T extends ObjectLiteral>(

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(
Expand Down