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 34
34
"size-limit" : [
35
35
{
36
36
"path" : " dist/index.js" ,
37
- "limit" : " 1.7 kB"
37
+ "limit" : " 1.75 kB"
38
38
}
39
39
],
40
40
"jest" : {
Original file line number Diff line number Diff line change @@ -2832,6 +2832,14 @@ describe("path-to-regexp", function() {
2832
2832
] ) ;
2833
2833
} ) ;
2834
2834
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
+
2835
2843
it ( "should fix repeated slashes" , function ( ) {
2836
2844
const input = encodeURI ( "/test///route" ) ;
2837
2845
Original file line number Diff line number Diff line change @@ -19,9 +19,20 @@ export interface ParseOptions {
19
19
* slash and normalizes unicode characters to "NFC". When using this method,
20
20
* `decode` should be an identity function so you don't decode strings twice.
21
21
*/
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
24
27
. 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
+ )
25
36
. normalize ( ) ;
26
37
}
27
38
You can’t perform that action at this time.
0 commit comments