Skip to content

Commit 0e9d248

Browse files
authored
Add back support for unencoded folder/workspace query params (#15)
* Add back support for unencoded folder/workspace query params Fixes coder/code-server#4484. * Standardize on @author for marking our changes
1 parent 8db6c9b commit 0e9d248

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

src/vs/code/browser/workbench/workbench.ts

+51-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ function doCreateUri(path: string, queryValues: Map<string, string>): URI {
3737
return URI.parse(window.location.href).with({ path, query });
3838
}
3939

40+
/**
41+
* Encode a path for opening via the folder or workspace query parameter. This
42+
* preserves slashes so it can be edited by hand more easily.
43+
*
44+
* @author coder
45+
*/
46+
export const encodePath = (path: string): string => {
47+
return path.split('/').map((p) => encodeURIComponent(p)).join('/');
48+
};
49+
4050
interface ICredential {
4151
service: string;
4252
account: string;
@@ -319,13 +329,27 @@ class WorkspaceProvider implements IWorkspaceProvider {
319329
}
320330

321331
// Folder
332+
/**
333+
* Modified to print as a human-readable string for file paths.
334+
* @author coder
335+
*/
322336
else if (isFolderToOpen(workspace)) {
323-
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_FOLDER}=${encodeURIComponent(workspace.folderUri.toString())}`;
337+
const target = workspace.folderUri.scheme === Schemas.vscodeRemote
338+
? encodePath(workspace.folderUri.path)
339+
: encodeURIComponent(workspace.folderUri.toString());
340+
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_FOLDER}=${target}`;
324341
}
325342

326343
// Workspace
344+
/**
345+
* Modified to print as a human-readable string for file paths.
346+
* @author coder
347+
*/
327348
else if (isWorkspaceToOpen(workspace)) {
328-
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_WORKSPACE}=${encodeURIComponent(workspace.workspaceUri.toString())}`;
349+
const target = workspace.workspaceUri.scheme === Schemas.vscodeRemote
350+
? encodePath(workspace.workspaceUri.path)
351+
: encodeURIComponent(workspace.workspaceUri.toString());
352+
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_WORKSPACE}=${target}`;
329353
}
330354

331355
// Append payload if any
@@ -423,18 +447,42 @@ class WindowIndicator implements IWindowIndicator {
423447
let payload = Object.create(null);
424448
let logLevel: string | undefined = undefined;
425449

450+
/**
451+
* If the value begins with a slash assume it is a file path and convert it to
452+
* use the vscode-remote scheme.
453+
*
454+
* @author coder
455+
*/
456+
const toRemote = (value: string): string => {
457+
if (value.startsWith("/")) {
458+
return "vscode-remote://" + value;
459+
}
460+
return value
461+
}
462+
426463
const query = new URL(document.location.href).searchParams;
427464
query.forEach((value, key) => {
428465
switch (key) {
429-
430466
// Folder
431467
case WorkspaceProvider.QUERY_PARAM_FOLDER:
468+
/**
469+
* Handle URIs that we previously left unencoded and de-schemed.
470+
*
471+
* @author coder
472+
*/
473+
value = toRemote(value);
432474
workspace = { folderUri: URI.parse(value) };
433475
foundWorkspace = true;
434476
break;
435477

436478
// Workspace
437479
case WorkspaceProvider.QUERY_PARAM_WORKSPACE:
480+
/**
481+
* Handle URIs that we previously left unencoded and de-schemed.
482+
*
483+
* @author coder
484+
*/
485+
value = toRemote(value);
438486
workspace = { workspaceUri: URI.parse(value) };
439487
foundWorkspace = true;
440488
break;

0 commit comments

Comments
 (0)