@@ -65,7 +65,7 @@ type Layer = {
65
65
route ?: { path : RouteType | RouteType [ ] } ;
66
66
path ?: string ;
67
67
regexp ?: RegExp ;
68
- keys ?: { name : string ; offset : number ; optional : boolean } [ ] ;
68
+ keys ?: { name : string | number ; offset : number ; optional : boolean } [ ] ;
69
69
} ;
70
70
71
71
type RouteType = string | RegExp ;
@@ -433,30 +433,34 @@ export const extractOriginalRoute = (
433
433
/**
434
434
* iterate param matches from regexp.exec
435
435
*/
436
- paramIndices . forEach ( ( [ startOffset , endOffset ] , index : number ) => {
437
- /**
438
- * isolate part before param
439
- */
440
- const substr1 = resultPath . substring ( 0 , startOffset - indexShift ) ;
441
- /**
442
- * define paramName as replacement in format :pathParam
443
- */
444
- const replacement = `:${ orderedKeys [ index ] . name } ` ;
445
-
446
- /**
447
- * isolate part after param
448
- */
449
- const substr2 = resultPath . substring ( endOffset - indexShift ) ;
450
-
451
- /**
452
- * recreate original path but with param replacement
453
- */
454
- resultPath = substr1 + replacement + substr2 ;
455
-
456
- /**
457
- * calculate new index shift after resultPath was modified
458
- */
459
- indexShift = indexShift + ( endOffset - startOffset - replacement . length ) ;
436
+ paramIndices . forEach ( ( item : [ number , number ] | undefined , index : number ) => {
437
+ /** check if offsets is define because in some cases regex d flag returns undefined */
438
+ if ( item ) {
439
+ const [ startOffset , endOffset ] = item ;
440
+ /**
441
+ * isolate part before param
442
+ */
443
+ const substr1 = resultPath . substring ( 0 , startOffset - indexShift ) ;
444
+ /**
445
+ * define paramName as replacement in format :pathParam
446
+ */
447
+ const replacement = `:${ orderedKeys [ index ] . name } ` ;
448
+
449
+ /**
450
+ * isolate part after param
451
+ */
452
+ const substr2 = resultPath . substring ( endOffset - indexShift ) ;
453
+
454
+ /**
455
+ * recreate original path but with param replacement
456
+ */
457
+ resultPath = substr1 + replacement + substr2 ;
458
+
459
+ /**
460
+ * calculate new index shift after resultPath was modified
461
+ */
462
+ indexShift = indexShift + ( endOffset - startOffset - replacement . length ) ;
463
+ }
460
464
} ) ;
461
465
462
466
return resultPath ;
0 commit comments