File tree Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -179,14 +179,23 @@ describe("path matching with a basename", () => {
179
179
} ) ;
180
180
181
181
describe ( "path matching with splats" , ( ) => {
182
- test ( "splat after /" , ( ) => {
182
+ describe ( "splat after /" , ( ) => {
183
183
let routes = [ { path : "users/:id/files/*" } ] ;
184
184
let match = matchRoutes ( routes , "/users/mj/files/secrets.md" ) ;
185
185
186
- expect ( match ) . not . toBeNull ( ) ;
187
- expect ( match [ 0 ] ) . toMatchObject ( {
188
- params : { id : "mj" , "*" : "secrets.md" } ,
189
- pathname : "/users/mj/files"
186
+ it ( "finds the correct match" , ( ) => {
187
+ expect ( match ) . not . toBeNull ( ) ;
188
+ expect ( match [ 0 ] ) . toMatchObject ( {
189
+ pathname : "/users/mj/files" ,
190
+ params : { id : "mj" , "*" : "secrets.md" }
191
+ } ) ;
192
+ } ) ;
193
+
194
+ describe ( "when other characters come before the /" , ( ) => {
195
+ it ( "does not find a match" , ( ) => {
196
+ let match = matchRoutes ( routes , "/users/mj/filesssss/secrets.md" ) ;
197
+ expect ( match ) . toBeNull ( ) ;
198
+ } ) ;
190
199
} ) ;
191
200
} ) ;
192
201
Original file line number Diff line number Diff line change @@ -908,7 +908,7 @@ export function matchPath(
908
908
let matchedPathname = match [ 1 ] ;
909
909
let values = match . slice ( 2 ) ;
910
910
let params = paramNames . reduce ( ( memo , paramName , index ) => {
911
- memo [ paramName ] = safelyDecodeURIComponent ( values [ index ] , paramName ) ;
911
+ memo [ paramName ] = safelyDecodeURIComponent ( values [ index ] || "" , paramName ) ;
912
912
return memo ;
913
913
} , { } as Params ) ;
914
914
@@ -941,10 +941,11 @@ function compilePath(
941
941
942
942
if ( path . endsWith ( "*" ) ) {
943
943
if ( path . endsWith ( "/*" ) ) {
944
- source += "\\/?" ; // Don't include the / in params['*']
944
+ source += "(?:\\/(.+)|\\/?)" ; // Don't include the / in params['*']
945
+ } else {
946
+ source += "(.*)" ;
945
947
}
946
948
keys . push ( "*" ) ;
947
- source += "(.*)" ;
948
949
} else if ( end ) {
949
950
source += "\\/?" ;
950
951
}
You can’t perform that action at this time.
0 commit comments