Skip to content

Commit e8e5794

Browse files
authored
fix: social regex unicode support (#5133)
Related dailydotdev/daily#1507
1 parent f8309d7 commit e8e5794

2 files changed

Lines changed: 89 additions & 2 deletions

File tree

packages/shared/src/graphql/users.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,13 @@ export const REMOVE_USER_COMPANY_MUTATION = gql`
440440
`;
441441

442442
// Regex taken from https://github.com/dailydotdev/daily-api/blob/234b0be53fea85954403cef5a2326fc50ce498fd/src/common/object.ts#L41
443-
export const handleRegex = new RegExp(/^@?[a-z0-9](\w){2,38}$/i);
443+
// Updated to support Unicode word characters (including accented characters)
444+
export const handleRegex = new RegExp(
445+
/^@?[\p{L}\p{N}]([\p{L}\p{N}_]){2,38}$/iu,
446+
);
444447
// Regex taken from https://github.com/dailydotdev/daily-api/blob/234b0be53fea85954403cef5a2326fc50ce498fd/src/common/object.ts#L40
445-
export const socialHandleRegex = new RegExp(/^@?([\w-]){1,39}$/i);
448+
// Updated to support Unicode word characters (including accented characters)
449+
export const socialHandleRegex = new RegExp(/^@?([\p{L}\p{N}_-]){1,39}$/iu);
446450

447451
export const REFERRAL_CAMPAIGN_QUERY = gql`
448452
query ReferralCampaign($referralOrigin: String!) {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { onValidateHandles } from '../useProfileForm';
2+
3+
describe('onValidateHandles', () => {
4+
it('should accept accented characters in social handles', () => {
5+
const before = {};
6+
const after = {
7+
twitter: 'ítalo-oliveira-800923162',
8+
github: 'José',
9+
linkedin: 'François',
10+
username: 'Müller',
11+
};
12+
13+
const result = onValidateHandles(before, after);
14+
15+
expect(result).toEqual({});
16+
});
17+
18+
it('should accept accented characters in username', () => {
19+
const before = { username: 'oldname' };
20+
const after = { username: 'José_González' };
21+
22+
const result = onValidateHandles(before, after);
23+
24+
expect(result).toEqual({});
25+
});
26+
27+
it('should accept Unicode characters from various languages', () => {
28+
const before = {};
29+
const after = {
30+
username: 'Борис', // Cyrillic
31+
twitter: '北京', // Chinese
32+
github: 'جوزيف', // Arabic
33+
};
34+
35+
const result = onValidateHandles(before, after);
36+
37+
expect(result).toEqual({});
38+
});
39+
40+
it('should accept mixed Unicode and ASCII characters', () => {
41+
const before = {};
42+
const after = {
43+
twitter: '@José-González_123',
44+
github: 'François-dev',
45+
username: 'Müller_Corp',
46+
};
47+
48+
const result = onValidateHandles(before, after);
49+
50+
expect(result).toEqual({});
51+
});
52+
53+
it('should still accept regular ASCII usernames', () => {
54+
const before = {};
55+
const after = {
56+
username: 'john_doe',
57+
twitter: '@johndoe',
58+
github: 'johndoe-dev',
59+
};
60+
61+
const result = onValidateHandles(before, after);
62+
63+
expect(result).toEqual({});
64+
});
65+
66+
it('should reject usernames that are too short', () => {
67+
const before = { username: 'oldname' };
68+
const after = { username: 'í' }; // Single character
69+
70+
const result = onValidateHandles(before, after);
71+
72+
expect(result.username).toBeDefined();
73+
});
74+
75+
it('should reject empty usernames', () => {
76+
const before = { username: 'oldname' };
77+
const after = { username: '' };
78+
79+
const result = onValidateHandles(before, after);
80+
81+
expect(result.username).toBeDefined();
82+
});
83+
});

0 commit comments

Comments
 (0)