Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit fa687c8

Browse files
committed
Revert "Simplify path2uri"
This reverts commit 01e7781.
1 parent 01e7781 commit fa687c8

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/util.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,20 @@ export function convertStringtoSymbolKind(kind: string): SymbolKind {
8484
* The returned URL uses protocol and host of the passed root URL
8585
*/
8686
export function path2uri(rootUri: URL, filePath: string): URL {
87-
let pathname = filePath.replace(/\\/g, '/');
88-
if (/^\/[a-z]:\//i.test(pathname)) {
89-
pathname = '/' + pathname;
87+
const parts = filePath.split(/[\\\/]/);
88+
const isWindowsUri = parts[0].endsWith(':');
89+
// Don't encode colon after Windows drive letter
90+
if (isWindowsUri) {
91+
parts[0] = '/' + parts[0];
92+
} else {
93+
parts[0] = encodeURIComponent(parts[0]);
94+
}
95+
// Encode all other parts
96+
for (let i = 1; i < parts.length; i++) {
97+
parts[i] = encodeURIComponent(parts[i]);
9098
}
91-
const uri = new URL(rootUri.href);
92-
uri.pathname = pathname;
93-
return uri;
99+
const pathname = parts.join(isWindowsUri ? '\\' : '/');
100+
return new URL(pathname, rootUri.href);
94101
}
95102

96103
/**

0 commit comments

Comments
 (0)