File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -359,21 +359,31 @@ function normalizeRouteSrc(route: string): string {
359359 . split ( "/" )
360360 . map ( ( segment ) => {
361361 if ( segment . startsWith ( "**" ) ) {
362- return segment === "**" ? "?(?<_>.*)" : `?(?<${ segment . slice ( 3 ) } >.+)` ;
362+ return segment === "**"
363+ ? "(?:.*)"
364+ : `?(?<${ namedGroup ( segment . slice ( 3 ) ) } >.+)` ;
363365 }
364366 if ( segment === "*" ) {
365367 return `(?<_${ idCtr ++ } >[^/]*)` ;
366368 }
367369 if ( segment . includes ( ":" ) ) {
368370 return segment
369- . replace ( / : ( \w + ) / g, ( _ , id ) => `(?<${ id } >[^/]+)` )
371+ . replace ( / : ( \w + ) / g, ( _ , id ) => `(?<${ namedGroup ( id ) } >[^/]+)` )
370372 . replace ( / \. / g, String . raw `\.` ) ;
371373 }
372374 return segment ;
373375 } )
374376 . join ( "/" ) ;
375377}
376378
379+ // Valid PCRE capture group name
380+ function namedGroup ( input = "" ) {
381+ if ( / \d / . test ( input [ 0 ] ) ) {
382+ input = `_${ input } ` ;
383+ }
384+ return input . replace ( / [ ^ a - z A - Z 0 - 9 _ ] / g, "" ) || "_" ;
385+ }
386+
377387// Output is a destination pathname to function name
378388function normalizeRouteDest ( route : string ) {
379389 return (
Original file line number Diff line number Diff line change @@ -422,7 +422,7 @@ describe("nitro:preset:vercel", async () => {
422422 },
423423 {
424424 "dest": "/api/typed/todos/[...]",
425- "src": "/api/typed/todos/?(?<_> .*)",
425+ "src": "/api/typed/todos/(?: .*)",
426426 },
427427 {
428428 "dest": "/api/typed/todos/[todoId]/comments/[...commentId]",
You can’t perform that action at this time.
0 commit comments