Skip to content

Commit d478f97

Browse files
committed
Update UID parser to handle "unverified" identities
1 parent 8c01af9 commit d478f97

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/utils/user.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ describe('user', () => {
99
});
1010

1111
it('parses UID from ident or former nick format', () => {
12-
expect(parseUid('AnotherUser', 'anon')).toBe('anon');
12+
expect(parseUid('AnotherUser', 'anon')).toBe('0');
13+
expect(parseUid('Someone', '~987')).toBe('987');
1314
expect(parseUid('Anonymous^456', '67890')).toBe('67890');
1415
expect(parseUid('Chatter__123^1', 'anon')).toBe('123');
1516
});

src/utils/user.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ export function parseNick(nick: string) {
2020
}
2121
}
2222

23+
const UID_REGEX = /^~?(\d+)$/i;
24+
2325
export function parseUid(nick: string, uid: string): string {
24-
if (uid === 'anon') {
26+
const uidMatch = UID_REGEX.exec(uid);
27+
if (uidMatch) {
28+
return uidMatch[1];
29+
} else if (uid === 'anon') {
2530
const match = LEGACY_UID_REGEX.exec(nick);
2631
if (match) {
2732
return match[1];
33+
} else {
34+
return '0';
2835
}
2936
}
3037

31-
return uid;
38+
return '0';
3239
}

0 commit comments

Comments
 (0)