This repository was archived by the owner on Jun 27, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -33,14 +33,14 @@ describe('pathToRegExp', () => {
3333 describe ( 'given a path with a wildcard' , ( ) => {
3434 it ( 'should handle wildcard' , ( ) => {
3535 const exp = pathToRegExp ( '/user/*/shipping' )
36- expect ( exp ) . toEqual ( / \/ u s e r \/ .+ \/ s h i p p i n g ( \/ | $ ) / gi)
36+ expect ( exp ) . toEqual ( / \/ u s e r \/ .* \/ s h i p p i n g ( \/ | $ ) / gi)
3737 } )
3838 } )
3939
4040 describe ( 'given a path with parameter and wildcard' , ( ) => {
4141 it ( 'should handle both' , ( ) => {
4242 const exp = pathToRegExp ( '/user/:userId/*' )
43- expect ( exp ) . toEqual ( / \/ u s e r \/ (?< userId > [ ^ / ] + ?) \/ .+ ( \/ | $ ) / gi)
43+ expect ( exp ) . toEqual ( / \/ u s e r \/ (?< userId > [ ^ / ] + ?) \/ .* ( \/ | $ ) / gi)
4444 } )
4545 } )
4646
Original file line number Diff line number Diff line change @@ -12,12 +12,12 @@ export const pathToRegExp = (path: string): RegExp => {
1212 . replace ( / \? / g, '\\?' )
1313 // Ignore trailing slashes
1414 . replace ( / \/ + $ / , '' )
15- // Replace wildcard with any single character sequence
16- . replace ( / \* + / g, '.+ ' )
15+ // Replace wildcard with any zero-to-any character sequence
16+ . replace ( / \* + / g, '.* ' )
1717 // Replace parameters with named capturing groups
1818 . replace (
1919 / : ( [ ^ \d | ^ \/ ] [ a - z A - Z 0 - 9 _ ] * (? = (?: \/ | \\ .) | $ ) ) / g,
20- ( _ , match ) => `(?<${ match } >[^\/]+?)` ,
20+ ( _ , paramName ) => `(?<${ paramName } >[^\/]+?)` ,
2121 )
2222 // Allow optional trailing slash
2323 . concat ( '(\\/|$)' )
Original file line number Diff line number Diff line change @@ -288,6 +288,25 @@ runner('Path', [
288288 } ,
289289 ] ,
290290 } ,
291+ {
292+ given : '/user/details*' ,
293+ when : [
294+ {
295+ actual : '/user/details' ,
296+ it : {
297+ matches : true ,
298+ params : null ,
299+ } ,
300+ } ,
301+ {
302+ actual : '/user/details/arbitrary' ,
303+ it : {
304+ matches : true ,
305+ params : null ,
306+ } ,
307+ } ,
308+ ] ,
309+ } ,
291310
292311 /**
293312 * Parameter and wildcard
You can’t perform that action at this time.
0 commit comments