Skip to content

Commit f7f11ad

Browse files
committed
Fix paths from Windows client to non-Windows server
Fixes #1659 Fixes #1642
1 parent 0c2381f commit f7f11ad

File tree

4 files changed

+57
-9
lines changed

4 files changed

+57
-9
lines changed

ci/dev/vscode.patch

+5-7
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,17 @@ index 1e16cde724..0000000000
248248
-target "12.4.0"
249249
-runtime "node"
250250
diff --git a/src/vs/base/common/network.ts b/src/vs/base/common/network.ts
251-
index e4546b2cf6..9df12239fb 100644
251+
index e4546b2cf6..ad2c544e89 100644
252252
--- a/src/vs/base/common/network.ts
253253
+++ b/src/vs/base/common/network.ts
254-
@@ -94,16 +94,18 @@ class RemoteAuthoritiesImpl {
254+
@@ -94,16 +94,17 @@ class RemoteAuthoritiesImpl {
255255
if (host && host.indexOf(':') !== -1) {
256256
host = `[${host}]`;
257257
}
258258
- const port = this._ports[authority];
259259
+ // const port = this._ports[authority];
260260
const connectionToken = this._connectionTokens[authority];
261-
- let query = `path=${encodeURIComponent(uri.path)}`;
262-
+ // NOTE@coder: Use fsPath for Windows support.
263-
+ let query = `path=${encodeURIComponent(uri.fsPath)}`;
261+
let query = `path=${encodeURIComponent(uri.path)}`;
264262
if (typeof connectionToken === 'string') {
265263
query += `&tkn=${encodeURIComponent(connectionToken)}`;
266264
}
@@ -1067,7 +1065,7 @@ index 0000000000..0d2e93edae
10671065
+}
10681066
diff --git a/src/vs/server/browser/worker.ts b/src/vs/server/browser/worker.ts
10691067
new file mode 100644
1070-
index 0000000000..8db1e17c38
1068+
index 0000000000..a93381631a
10711069
--- /dev/null
10721070
+++ b/src/vs/server/browser/worker.ts
10731071
@@ -0,0 +1,57 @@
@@ -1090,7 +1088,7 @@ index 0000000000..8db1e17c38
10901088
+ scheme: self.location.protocol.replace(':', ''),
10911089
+ authority: self.location.host,
10921090
+ path: self.location.pathname.replace(/\/static\/([^\/]+)\/.*$/, '/static/$1\/'),
1093-
+ query: `tar=${encodeURIComponent(module.extensionLocation.fsPath)}`,
1091+
+ query: `tar=${encodeURIComponent(module.extensionLocation.path)}`,
10941092
+ });
10951093
+ const response = await fetch(fetchUri.toString(true));
10961094
+ if (response.status !== 200) {

src/node/app/static.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Readable } from "stream"
55
import * as tarFs from "tar-fs"
66
import * as zlib from "zlib"
77
import { HttpProvider, HttpResponse, Route } from "../http"
8+
import { pathToFsPath } from "../util"
89

910
/**
1011
* Static file HTTP provider. Regular static requests (the path is the request
@@ -18,7 +19,7 @@ export class StaticHttpProvider extends HttpProvider {
1819

1920
if (typeof route.query.tar === "string") {
2021
this.ensureAuthenticated(request)
21-
return this.getTarredResource(request, route.query.tar)
22+
return this.getTarredResource(request, pathToFsPath(route.query.tar))
2223
}
2324

2425
const response = await this.getReplacedResource(route)

src/node/app/vscode.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { generateUuid } from "../../common/util"
1818
import { Args } from "../cli"
1919
import { HttpProvider, HttpProviderOptions, HttpResponse, Route } from "../http"
2020
import { settings } from "../settings"
21+
import { pathToFsPath } from "../util"
2122

2223
export class VscodeHttpProvider extends HttpProvider {
2324
private readonly serverRootPath: string
@@ -151,7 +152,7 @@ export class VscodeHttpProvider extends HttpProvider {
151152
case "/resource":
152153
case "/vscode-remote-resource":
153154
if (typeof route.query.path === "string") {
154-
return this.getResource(route.query.path)
155+
return this.getResource(pathToFsPath(route.query.path))
155156
}
156157
break
157158
case "/webview":

src/node/util.ts

+48
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,51 @@ export function extend(...args: any[]): any {
217217
}
218218
return c
219219
}
220+
221+
/**
222+
* Taken from vs/base/common/charCode.ts. Copied for now instead of importing so
223+
* we don't have to set up a `vs` alias to be able to import with types (since
224+
* the alternative is to directly import from `out`).
225+
*/
226+
const enum CharCode {
227+
Slash = 47,
228+
A = 65,
229+
Z = 90,
230+
a = 97,
231+
z = 122,
232+
Colon = 58,
233+
}
234+
235+
/**
236+
* Compute `fsPath` for the given uri.
237+
* Taken from vs/base/common/uri.ts. It's not imported to avoid also importing
238+
* everything that file imports.
239+
*/
240+
export function pathToFsPath(path: string, keepDriveLetterCasing = false): string {
241+
const isWindows = process.platform === "win32"
242+
const uri = { authority: undefined, path, scheme: "file" }
243+
let value: string
244+
if (uri.authority && uri.path.length > 1 && uri.scheme === "file") {
245+
// unc path: file://shares/c$/far/boo
246+
value = `//${uri.authority}${uri.path}`
247+
} else if (
248+
uri.path.charCodeAt(0) === CharCode.Slash &&
249+
((uri.path.charCodeAt(1) >= CharCode.A && uri.path.charCodeAt(1) <= CharCode.Z) ||
250+
(uri.path.charCodeAt(1) >= CharCode.a && uri.path.charCodeAt(1) <= CharCode.z)) &&
251+
uri.path.charCodeAt(2) === CharCode.Colon
252+
) {
253+
if (!keepDriveLetterCasing) {
254+
// windows drive letter: file:///c:/far/boo
255+
value = uri.path[1].toLowerCase() + uri.path.substr(2)
256+
} else {
257+
value = uri.path.substr(1)
258+
}
259+
} else {
260+
// other path
261+
value = uri.path
262+
}
263+
if (isWindows) {
264+
value = value.replace(/\//g, "\\")
265+
}
266+
return value
267+
}

0 commit comments

Comments
 (0)