File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed
Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ describe('getConversationId', () => {
6666 it ( 'should only contain URL-safe characters' , ( ) => {
6767 // nanoid uses A-Za-z0-9_- alphabet
6868 // After lowercase conversion: a-z0-9_-
69- const urlSafePattern = / ^ [ a - z 0 - 9 _ - ] + $ / ;
69+ const urlSafePattern = / ^ [ a - z 0 - 9 ] + $ / ;
7070
7171 for ( let i = 0 ; i < 50 ; i ++ ) {
7272 const id = getConversationId ( ) ;
@@ -86,7 +86,7 @@ describe('getConversationId', () => {
8686 // IDs should be valid
8787 for ( const id of ids ) {
8888 expect ( id . length ) . toBeGreaterThan ( 0 ) ;
89- expect ( / ^ [ a - z 0 - 9 _ - ] + $ / . test ( id ) ) . toBe ( true ) ;
89+ expect ( / ^ [ a - z 0 - 9 ] + $ / . test ( id ) ) . toBe ( true ) ;
9090 }
9191 } ) ;
9292 } ) ;
Original file line number Diff line number Diff line change 1- import { nanoid } from 'nanoid' ;
1+ import { customAlphabet } from 'nanoid' ;
2+
3+ // Create a custom nanoid generator with only lowercase letters and numbers
4+ // This ensures IDs are always lowercase and never start with a hyphen
5+ const generateId = customAlphabet ( 'abcdefghijklmnopqrstuvwxyz0123456789' , 21 ) ;
26
37/**
48 * Generates a standardized conversation ID.
@@ -15,10 +19,5 @@ import { nanoid } from 'nanoid';
1519 * ```
1620 */
1721export function getConversationId ( ) : string {
18- let id = nanoid ( ) ;
19-
20- // Convert to lowercase and remove any leading hyphens
21- id = id . toLowerCase ( ) . replace ( / ^ - + / , '' ) ;
22-
23- return id ;
22+ return generateId ( ) ;
2423}
You can’t perform that action at this time.
0 commit comments