Skip to content

Commit 0712758

Browse files
committed
Fix paths from Windows client to non-Windows server
Fixes #1659 Fixes #1642
1 parent 8626bed commit 0712758

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
}
@@ -1054,7 +1052,7 @@ index 0000000000..0d2e93edae
10541052
+}
10551053
diff --git a/src/vs/server/browser/worker.ts b/src/vs/server/browser/worker.ts
10561054
new file mode 100644
1057-
index 0000000000..8db1e17c38
1055+
index 0000000000..a93381631a
10581056
--- /dev/null
10591057
+++ b/src/vs/server/browser/worker.ts
10601058
@@ -0,0 +1,57 @@
@@ -1077,7 +1075,7 @@ index 0000000000..8db1e17c38
10771075
+ scheme: self.location.protocol.replace(':', ''),
10781076
+ authority: self.location.host,
10791077
+ path: self.location.pathname.replace(/\/static\/([^\/]+)\/.*$/, '/static/$1\/'),
1080-
+ query: `tar=${encodeURIComponent(module.extensionLocation.fsPath)}`,
1078+
+ query: `tar=${encodeURIComponent(module.extensionLocation.path)}`,
10811079
+ });
10821080
+ const response = await fetch(fetchUri.toString(true));
10831081
+ 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
@@ -224,3 +224,51 @@ export function extend(...args: any[]): any {
224224
}
225225
return c
226226
}
227+
228+
/**
229+
* Taken from vs/base/common/charCode.ts. Copied for now instead of importing so
230+
* we don't have to set up a `vs` alias to be able to import with types (since
231+
* the alternative is to directly import from `out`).
232+
*/
233+
const enum CharCode {
234+
Slash = 47,
235+
A = 65,
236+
Z = 90,
237+
a = 97,
238+
z = 122,
239+
Colon = 58,
240+
}
241+
242+
/**
243+
* Compute `fsPath` for the given uri.
244+
* Taken from vs/base/common/uri.ts. It's not imported to avoid also importing
245+
* everything that file imports.
246+
*/
247+
export function pathToFsPath(path: string, keepDriveLetterCasing = false): string {
248+
const isWindows = process.platform === "win32"
249+
const uri = { authority: undefined, path, scheme: "file" }
250+
let value: string
251+
if (uri.authority && uri.path.length > 1 && uri.scheme === "file") {
252+
// unc path: file://shares/c$/far/boo
253+
value = `//${uri.authority}${uri.path}`
254+
} else if (
255+
uri.path.charCodeAt(0) === CharCode.Slash &&
256+
((uri.path.charCodeAt(1) >= CharCode.A && uri.path.charCodeAt(1) <= CharCode.Z) ||
257+
(uri.path.charCodeAt(1) >= CharCode.a && uri.path.charCodeAt(1) <= CharCode.z)) &&
258+
uri.path.charCodeAt(2) === CharCode.Colon
259+
) {
260+
if (!keepDriveLetterCasing) {
261+
// windows drive letter: file:///c:/far/boo
262+
value = uri.path[1].toLowerCase() + uri.path.substr(2)
263+
} else {
264+
value = uri.path.substr(1)
265+
}
266+
} else {
267+
// other path
268+
value = uri.path
269+
}
270+
if (isWindows) {
271+
value = value.replace(/\//g, "\\")
272+
}
273+
return value
274+
}

0 commit comments

Comments
 (0)