File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 3434 "size-limit" : [
3535 {
3636 "path" : " dist/index.js" ,
37- "limit" : " 1.7 kB"
37+ "limit" : " 1.75 kB"
3838 }
3939 ],
4040 "jest" : {
Original file line number Diff line number Diff line change @@ -2832,6 +2832,14 @@ describe("path-to-regexp", function() {
28322832 ] ) ;
28332833 } ) ;
28342834
2835+ it ( "should not normalize whitelisted characters" , function ( ) {
2836+ const input = "/test/route%2F%25" ;
2837+
2838+ expect ( pathToRegexp . normalizePathname ( input ) ) . toEqual (
2839+ "/test/route%2F%25"
2840+ ) ;
2841+ } ) ;
2842+
28352843 it ( "should fix repeated slashes" , function ( ) {
28362844 const input = encodeURI ( "/test///route" ) ;
28372845
Original file line number Diff line number Diff line change @@ -19,9 +19,20 @@ export interface ParseOptions {
1919 * slash and normalizes unicode characters to "NFC". When using this method,
2020 * `decode` should be an identity function so you don't decode strings twice.
2121 */
22- export function normalizePathname ( pathname : string ) {
23- return decodeURIComponent ( pathname )
22+ export function normalizePathname (
23+ pathname : string ,
24+ whitelist : string | string [ ] = "%/-."
25+ ) {
26+ return pathname
2427 . replace ( / \/ + / g, "/" )
28+ . replace (
29+ / (?: % [ e f ] [ 0 - 9 a - f ] (?: % [ 0 - 9 a - f ] { 2 } ) { 2 } | % [ c d ] [ 0 - 9 a - f ] % [ 0 - 9 a - f ] { 2 } | % [ 0 - 9 a - f ] { 2 } ) / gi,
30+ function ( m ) {
31+ const char = decodeURIComponent ( m ) ;
32+ if ( whitelist . indexOf ( char ) > - 1 ) return m ;
33+ return char ;
34+ }
35+ )
2536 . normalize ( ) ;
2637}
2738
You can’t perform that action at this time.
0 commit comments