File tree Expand file tree Collapse file tree 1 file changed +7
-18
lines changed Expand file tree Collapse file tree 1 file changed +7
-18
lines changed Original file line number Diff line number Diff line change @@ -11,32 +11,21 @@ function ignoreNotfoundError(error: any): null {
11
11
* Normalize a path, removing empty segments and leading/trailing slashes
12
12
*/
13
13
export function normalizePath ( path : string ) : string {
14
- const normalizedWrappedPath = `/${ path } /`
15
- // Replace colons with slashes
16
- . replace ( / : / g, "/" )
17
-
18
- // Remove . segments
19
- . replace ( / \/ \. \/ / g, "/" )
20
-
21
- // Remove duplicate slashes
22
- . replace ( / \/ { 2 , } / g, "/" ) ;
14
+ // Wrap path in slashes, remove . segments and collapse subsequent namespace separators
15
+ const normalizedWrappedPath = `/${ path } /` . replace (
16
+ / [ / : ] + ( \. [ / : ] + ) * [ / : ] * / g,
17
+ "/"
18
+ ) ;
23
19
24
- // Disallow .. segments
20
+ // Prohibit .. segments
25
21
if ( normalizedWrappedPath . includes ( "/../" ) ) {
26
22
throw createError (
27
23
DRIVER_NAME ,
28
24
`Invalid key: ${ JSON . stringify ( path ) } . It must not contain .. segments`
29
25
) ;
30
26
}
31
27
32
- return (
33
- normalizedWrappedPath
34
- // Remove leading slashes
35
- . replace ( / ^ \/ / g, "" )
36
-
37
- // Remove trailing slashes
38
- . replace ( / \/ $ / g, "" )
39
- ) ;
28
+ return normalizedWrappedPath . slice ( 1 , - 1 ) ;
40
29
}
41
30
42
31
/**
You can’t perform that action at this time.
0 commit comments