Skip to content

Commit 6f09f5e

Browse files
authored
fix: linkedin regex acceptance (#3330)
1 parent 25ce869 commit 6f09f5e

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

__tests__/common/object.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { socialHandleRegex, handleRegex } from '../../src/common/object';
2+
3+
describe('Unicode regex patterns', () => {
4+
it('socialHandleRegex supports Unicode with optional @ prefix', () => {
5+
// Valid Unicode handles
6+
expect(socialHandleRegex.test('@José')).toBe(true);
7+
expect(socialHandleRegex.test('François-dev')).toBe(true);
8+
expect(socialHandleRegex.test('北京')).toBe(true);
9+
expect(socialHandleRegex.test('user_123')).toBe(true);
10+
expect(socialHandleRegex.test('@' + 'a'.repeat(39))).toBe(true);
11+
12+
// Invalid handles
13+
expect(socialHandleRegex.test('')).toBe(false);
14+
expect(socialHandleRegex.test('a'.repeat(40))).toBe(false);
15+
expect(socialHandleRegex.test('has space')).toBe(false);
16+
expect(socialHandleRegex.test('bad!char')).toBe(false);
17+
});
18+
19+
it('handleRegex supports Unicode without hyphens', () => {
20+
// Valid handles (3-39 chars, no hyphens)
21+
expect(handleRegex.test('abc')).toBe(true);
22+
expect(handleRegex.test('@user_name')).toBe(true);
23+
expect(handleRegex.test('Jöhn123')).toBe(true);
24+
expect(handleRegex.test('@' + 'a'.repeat(39))).toBe(true);
25+
26+
// Invalid handles
27+
expect(handleRegex.test('ab')).toBe(false); // too short
28+
expect(handleRegex.test('François-dev')).toBe(false); // has hyphen
29+
expect(handleRegex.test('bad handle')).toBe(false); // has space
30+
expect(handleRegex.test('a'.repeat(40))).toBe(false); // too long
31+
});
32+
});

src/common/object.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ export const validateRegex = <T extends ObjectLiteral>(
5151

5252
return mutatedData as T;
5353
};
54-
5554
export const nameRegex = new RegExp(/^(.){1,60}$/);
56-
export const socialHandleRegex = new RegExp(/^@?([\w-]){1,39}$/i);
57-
export const handleRegex = new RegExp(/^@?[a-z0-9](\w){2,38}$/i);
55+
// Updated to support Unicode word characters (including accented characters)
56+
export const socialHandleRegex = new RegExp(/^@?([\p{L}\p{N}_-]){1,39}$/iu);
57+
// Updated to support Unicode word characters (including accented characters)
58+
export const handleRegex = new RegExp(/^@?[\p{L}\p{N}]([\p{L}\p{N}_]){2,38}$/iu);
5859
export const descriptionRegex = new RegExp(/^[\S\s]{1,250}$/);
5960
// Originated from: https://github.com/colinhacks/zod/blob/8552233c77426f77d3586cc877f7aec1aa0aa45b/src/types.ts#L599-L600
6061
export const emailRegex = new RegExp(

0 commit comments

Comments
 (0)