Skip to content

Commit a6180cb

Browse files
code-asherZauberNerd
authored andcommitted
Add back support for unencoded folder/workspace query params (microsoft#15)
* Add back support for unencoded folder/workspace query params Fixes coder/code-server#4484. * Standardize on @author for marking our changes
1 parent f7d2b92 commit a6180cb

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

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

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ import product from 'vs/platform/product/common/product';
1717
import { isFolderToOpen, isWorkspaceToOpen } from 'vs/platform/windows/common/windows';
1818
import { create, ICredentialsProvider, IURLCallbackProvider, IWorkbenchConstructionOptions, IWorkspace, IWorkspaceProvider } from 'vs/workbench/workbench.web.api';
1919

20+
/**
21+
* Encode a path for opening via the folder or workspace query parameter. This
22+
* preserves slashes so it can be edited by hand more easily.
23+
*
24+
* @author coder
25+
*/
26+
export const encodePath = (path: string): string => {
27+
return path.split('/').map((p) => encodeURIComponent(p)).join('/');
28+
};
29+
2030
interface ICredential {
2131
service: string;
2232
account: string;
@@ -264,18 +274,43 @@ class WorkspaceProvider implements IWorkspaceProvider {
264274
let workspace: IWorkspace;
265275
let payload = Object.create(null);
266276

277+
/**
278+
* If the value begins with a slash assume it is a file path and convert it to
279+
* use the vscode-remote scheme.
280+
*
281+
* @author coder
282+
*/
283+
const toRemote = (value: string): string => {
284+
if (value.startsWith("/")) {
285+
return "vscode-remote://" + value;
286+
}
287+
return value
288+
}
289+
267290
const query = new URL(document.location.href).searchParams;
268291
query.forEach((value, key) => {
269292
switch (key) {
270293

271294
// Folder
272295
case WorkspaceProvider.QUERY_PARAM_FOLDER:
296+
/**
297+
* Handle URIs that we previously left unencoded and de-schemed.
298+
*
299+
* @author coder
300+
*/
301+
value = toRemote(value);
273302
workspace = { folderUri: URI.parse(value) };
274303
foundWorkspace = true;
275304
break;
276305

277306
// Workspace
278307
case WorkspaceProvider.QUERY_PARAM_WORKSPACE:
308+
/**
309+
* Handle URIs that we previously left unencoded and de-schemed.
310+
*
311+
* @author coder
312+
*/
313+
value = toRemote(value);
279314
workspace = { workspaceUri: URI.parse(value) };
280315
foundWorkspace = true;
281316
break;
@@ -352,13 +387,27 @@ class WorkspaceProvider implements IWorkspaceProvider {
352387
}
353388

354389
// Folder
390+
/**
391+
* Modified to print as a human-readable string for file paths.
392+
* @author coder
393+
*/
355394
else if (isFolderToOpen(workspace)) {
356-
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_FOLDER}=${encodeURIComponent(workspace.folderUri.toString())}`;
395+
const target = workspace.folderUri.scheme === Schemas.vscodeRemote
396+
? encodePath(workspace.folderUri.path)
397+
: encodeURIComponent(workspace.folderUri.toString());
398+
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_FOLDER}=${target}`;
357399
}
358400

359401
// Workspace
402+
/**
403+
* Modified to print as a human-readable string for file paths.
404+
* @author coder
405+
*/
360406
else if (isWorkspaceToOpen(workspace)) {
361-
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_WORKSPACE}=${encodeURIComponent(workspace.workspaceUri.toString())}`;
407+
const target = workspace.workspaceUri.scheme === Schemas.vscodeRemote
408+
? encodePath(workspace.workspaceUri.path)
409+
: encodeURIComponent(workspace.workspaceUri.toString());
410+
targetHref = `${document.location.origin}${document.location.pathname}?${WorkspaceProvider.QUERY_PARAM_WORKSPACE}=${target}`;
362411
}
363412

364413
// Append payload if any

0 commit comments

Comments
 (0)