@@ -5,7 +5,14 @@ type Test = [
55 pathToRegexp . Path ,
66 ( pathToRegexp . RegExpOptions & pathToRegexp . ParseOptions ) | undefined ,
77 pathToRegexp . Token [ ] ,
8- Array < [ string , ( string | undefined ) [ ] | null , pathToRegexp . Match ?] > ,
8+ Array <
9+ [
10+ string ,
11+ ( string | undefined ) [ ] | null ,
12+ pathToRegexp . Match ?,
13+ pathToRegexp . RegexpToFunctionOptions ?
14+ ]
15+ > ,
916 Array < [ any , string | null , pathToRegexp . TokensToFunctionOptions ?] >
1017] ;
1118
@@ -166,6 +173,17 @@ const TESTS: Test[] = [
166173 "/route" ,
167174 [ "/route" , "route" ] ,
168175 { path : "/route" , index : 0 , params : { test : "route" } }
176+ ] ,
177+ [
178+ "/caf%C3%A9" ,
179+ [ "/caf%C3%A9" , "caf%C3%A9" ] ,
180+ { path : "/caf%C3%A9" , index : 0 , params : { test : "caf%C3%A9" } }
181+ ] ,
182+ [
183+ "/caf%C3%A9" ,
184+ [ "/caf%C3%A9" , "caf%C3%A9" ] ,
185+ { path : "/caf%C3%A9" , index : 0 , params : { test : "café" } } ,
186+ { decode : decodeURIComponent }
169187 ]
170188 ] ,
171189 [
@@ -2732,7 +2750,7 @@ describe("path-to-regexp", function() {
27322750 "match" + ( opts ? " using " + util . inspect ( opts ) : "" ) ,
27332751 function ( ) {
27342752 matchCases . forEach ( function ( io ) {
2735- const [ pathname , matches , params ] = io ;
2753+ const [ pathname , matches , params , options ] = io ;
27362754 const message = `should ${
27372755 matches ? "" : "not "
27382756 } match ${ util . inspect ( pathname ) } `;
@@ -2742,7 +2760,7 @@ describe("path-to-regexp", function() {
27422760 } ) ;
27432761
27442762 if ( typeof path === "string" && params !== undefined ) {
2745- const match = pathToRegexp . match ( path ) ;
2763+ const match = pathToRegexp . match ( path , options ) ;
27462764
27472765 it ( message + " params" , function ( ) {
27482766 expect ( match ( pathname ) ) . toEqual ( params ) ;
@@ -2802,6 +2820,23 @@ describe("path-to-regexp", function() {
28022820 ) ;
28032821 } ) ;
28042822 } ) ;
2823+
2824+ describe ( "normalize pathname" , function ( ) {
2825+ it ( "should match normalized pathnames" , function ( ) {
2826+ const re = pathToRegexp . pathToRegexp ( "/caf\u00E9" ) ;
2827+ const input = encodeURI ( "/cafe\u0301" ) ;
2828+
2829+ expect ( exec ( re , pathToRegexp . normalizePathname ( input ) ) ) . toEqual ( [
2830+ "/caf\u00E9"
2831+ ] ) ;
2832+ } ) ;
2833+
2834+ it ( "should fix repeated slashes" , function ( ) {
2835+ const input = encodeURI ( "/test///route" ) ;
2836+
2837+ expect ( pathToRegexp . normalizePathname ( input ) ) . toEqual ( "/test/route" ) ;
2838+ } ) ;
2839+ } ) ;
28052840} ) ;
28062841
28072842/**
0 commit comments