File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -86,18 +86,29 @@ export function valueError(message: string, name?: string): Error {
86
86
return Error ( name ? `$${ name } : ${ message } .` : `${ message } .` ) ;
87
87
}
88
88
89
+ // Node changed its implementation of pathToFileURL:
90
+ // https://github.com/nodejs/node/pull/54545
91
+ const unsafePathToFileURL = url . pathToFileURL ( '~' ) . pathname . endsWith ( '~' ) ;
92
+
89
93
/** Converts a (possibly relative) path on the local filesystem to a URL. */
90
94
export function pathToUrlString ( path : string ) : string {
91
95
if ( p . isAbsolute ( path ) ) return url . pathToFileURL ( path ) . toString ( ) ;
92
96
93
97
// percent encode relative path like `pathToFileURL`
94
- return encodeURI ( path )
95
- . replace ( / [ # ? ] / g, encodeURIComponent )
96
- . replace (
97
- process . platform === 'win32' ? / % ( 5 B | 5 C | 5 D | 5 E | 7 C ) / g : / % ( 5 B | 5 D | 5 E | 7 C ) / g,
98
- decodeURIComponent ,
99
- )
100
- . replace ( / \\ / g, '/' ) ;
98
+ return unsafePathToFileURL
99
+ ? encodeURI ( path )
100
+ . replace ( / [ # ? ] / g, encodeURIComponent )
101
+ . replace (
102
+ process . platform === 'win32'
103
+ ? / % ( 5 B | 5 C | 5 D | 5 E | 7 C ) / g
104
+ : / % ( 5 B | 5 D | 5 E | 7 C ) / g,
105
+ decodeURIComponent ,
106
+ )
107
+ . replace ( / \\ / g, '/' )
108
+ : encodeURI ( path )
109
+ . replace ( / [ # ? ] / g, encodeURIComponent )
110
+ . replace ( / ~ / g, '%7E' )
111
+ . replace ( / \\ / g, '/' ) ;
101
112
}
102
113
103
114
/**
You can’t perform that action at this time.
0 commit comments