@@ -37,6 +37,16 @@ function doCreateUri(path: string, queryValues: Map<string, string>): URI {
37
37
return URI . parse ( window . location . href ) . with ( { path, query } ) ;
38
38
}
39
39
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
+
40
50
interface ICredential {
41
51
service : string ;
42
52
account : string ;
@@ -319,13 +329,27 @@ class WorkspaceProvider implements IWorkspaceProvider {
319
329
}
320
330
321
331
// Folder
332
+ /**
333
+ * Modified to print as a human-readable string for file paths.
334
+ * @author coder
335
+ */
322
336
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 } ` ;
324
341
}
325
342
326
343
// Workspace
344
+ /**
345
+ * Modified to print as a human-readable string for file paths.
346
+ * @author coder
347
+ */
327
348
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 } ` ;
329
353
}
330
354
331
355
// Append payload if any
@@ -423,18 +447,42 @@ class WindowIndicator implements IWindowIndicator {
423
447
let payload = Object . create ( null ) ;
424
448
let logLevel : string | undefined = undefined ;
425
449
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
+
426
463
const query = new URL ( document . location . href ) . searchParams ;
427
464
query . forEach ( ( value , key ) => {
428
465
switch ( key ) {
429
-
430
466
// Folder
431
467
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 ) ;
432
474
workspace = { folderUri : URI . parse ( value ) } ;
433
475
foundWorkspace = true ;
434
476
break ;
435
477
436
478
// Workspace
437
479
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 ) ;
438
486
workspace = { workspaceUri : URI . parse ( value ) } ;
439
487
foundWorkspace = true ;
440
488
break ;
0 commit comments