File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -355,6 +355,17 @@ describe("matchPath *", () => {
355
355
pathnameBase : "/users/foo*" ,
356
356
} ) ;
357
357
} ) ;
358
+
359
+ it ( "matches a URL with %0A (a newline character)" , ( ) => {
360
+ expect ( matchPath ( "*" , "/%0A" ) ) . toMatchObject ( {
361
+ pathname : "/%0A" ,
362
+ pathnameBase : "/" ,
363
+ } )
364
+ expect ( matchPath ( "*" , "/new%0Aline" ) ) . toMatchObject ( {
365
+ pathname : "/new%0Aline" ,
366
+ pathnameBase : "/" ,
367
+ } )
368
+ } )
358
369
} ) ;
359
370
360
371
describe ( "matchPath warnings" , ( ) => {
Original file line number Diff line number Diff line change @@ -65,6 +65,11 @@ describe("matchRoutes", () => {
65
65
expect ( pickPaths ( routes , "/hometypo" ) ) . toEqual ( [ "*" ] ) ;
66
66
} ) ;
67
67
68
+ it ( "matches root * routes for URLs containing %0A (a newline character)" , ( ) => {
69
+ expect ( pickPaths ( routes , "/%0A" ) ) . toEqual ( [ "*" ] ) ;
70
+ expect ( pickPaths ( routes , "/new%0Aline" ) ) . toEqual ( [ "*" ] ) ;
71
+ } ) ;
72
+
68
73
it ( "matches index routes with path correctly" , ( ) => {
69
74
expect ( pickPaths ( routes , "/withpath" ) ) . toEqual ( [ "/withpath" ] ) ;
70
75
} ) ;
Original file line number Diff line number Diff line change @@ -1255,6 +1255,9 @@ export function compilePath(
1255
1255
return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)" ;
1256
1256
}
1257
1257
) ;
1258
+ // If the URL contains %0A (a newline character),
1259
+ // the regular expression will not match correctly unless the s (single line) flag is set.
1260
+ let regexpFlags = [ "s" ] ;
1258
1261
1259
1262
if ( path . endsWith ( "*" ) ) {
1260
1263
params . push ( { paramName : "*" } ) ;
@@ -1278,7 +1281,9 @@ export function compilePath(
1278
1281
// Nothing to match for "" or "/"
1279
1282
}
1280
1283
1281
- let matcher = new RegExp ( regexpSource , caseSensitive ? undefined : "i" ) ;
1284
+ if ( ! caseSensitive ) regexpFlags . push ( "i" ) ;
1285
+
1286
+ let matcher = new RegExp ( regexpSource , regexpFlags . join ( "" ) ) ;
1282
1287
1283
1288
return [ matcher , params ] ;
1284
1289
}
You can’t perform that action at this time.
0 commit comments