File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 } ) ;
Original file line number Diff line number Diff line change @@ -20,13 +20,20 @@ export function parseNick(nick: string) {
2020 }
2121}
2222
23+ const UID_REGEX = / ^ ~ ? ( \d + ) $ / i;
24+
2325export 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}
You can’t perform that action at this time.
0 commit comments