File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
packages/tracing-internal Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -413,10 +413,9 @@ export const extractOriginalRoute = (
413
413
regexp ?: Layer [ 'regexp' ] ,
414
414
keys ?: Layer [ 'keys' ] ,
415
415
) : string | undefined => {
416
- if ( ! path || ! regexp || ! keys || Object . keys ( keys ) . length === 0 || ! keys [ 0 ] ?. offset ) {
416
+ if ( ! path || ! regexp || ! keys || Object . keys ( keys ) . length === 0 || keys [ 0 ] ?. offset === undefined || keys [ 0 ] ?. offset === null ) {
417
417
return undefined ;
418
418
}
419
-
420
419
const orderedKeys = keys . sort ( ( a , b ) => a . offset - b . offset ) ;
421
420
422
421
// add d flag for getting indices from regexp result
Original file line number Diff line number Diff line change @@ -87,13 +87,20 @@ if (major >= 16) {
87
87
expect ( extractOriginalRoute ( path , regex , [ key ] ) ) . toBeUndefined ( ) ;
88
88
} ) ;
89
89
90
- it ( 'should return the original route path when valid inputs are provided' , ( ) => {
90
+ it ( 'should return the original route path when valid inputs are provided first static value then dynamic ' , ( ) => {
91
91
const path = '/router/123' ;
92
92
const regex = / ^ \/ r o u t e r \/ ( \d + ) $ / ;
93
93
const keys = [ { name : 'pathParam' , offset : 8 , optional : false } ] ;
94
94
expect ( extractOriginalRoute ( path , regex , keys ) ) . toBe ( '/router/:pathParam' ) ;
95
95
} ) ;
96
96
97
+ it ( 'should return the original route path when valid inputs are provided first dynamic value then static' , ( ) => {
98
+ const path = '/123/router' ;
99
+ const regex = / ^ (?: \/ ( [ ^ / ] + ?) ) \/ r o u t e r \/ ? (? = \/ | $ ) / i;
100
+ const keys = [ { name : 'pathParam' , offset : 0 , optional : false } ] ;
101
+ expect ( extractOriginalRoute ( path , regex , keys ) ) . toBe ( '/:pathParam/router' ) ;
102
+ } ) ;
103
+
97
104
it ( 'should handle multiple parameters in the route' , ( ) => {
98
105
const path = '/user/42/profile/username' ;
99
106
const regex = / ^ \/ u s e r \/ ( \d + ) \/ p r o f i l e \/ ( \w + ) $ / ;
You can’t perform that action at this time.
0 commit comments