@@ -404,34 +404,13 @@ class WorkspaceProvider implements IWorkspaceProvider {
404
404
405
405
// Folder
406
406
else if ( isFolderToOpen ( workspace ) ) {
407
- let queryParamFolder : string ;
408
- if ( this . config . remoteAuthority && workspace . folderUri . scheme === Schemas . vscodeRemote ) {
409
- // when connected to a remote and having a folder
410
- // for that remote, only use the path as query
411
- // value to form shorter, nicer URLs.
412
- // ensure paths are absolute (begin with `/`)
413
- // clipboard: ltrim(workspace.folderUri.path, posix.sep)
414
- queryParamFolder = `${ posix . sep } ${ ltrim ( workspace . folderUri . path , posix . sep ) } ` ;
415
- } else {
416
- queryParamFolder = encodeURIComponent ( workspace . folderUri . toString ( true ) ) ;
417
- }
418
-
407
+ const queryParamFolder = this . encodeWorkspacePath ( workspace . folderUri ) ;
419
408
targetHref = `${ document . location . origin } ${ document . location . pathname } ?${ WorkspaceProvider . QUERY_PARAM_FOLDER } =${ queryParamFolder } ` ;
420
409
}
421
410
422
411
// Workspace
423
412
else if ( isWorkspaceToOpen ( workspace ) ) {
424
- let queryParamWorkspace : string ;
425
- if ( this . config . remoteAuthority && workspace . workspaceUri . scheme === Schemas . vscodeRemote ) {
426
- // when connected to a remote and having a workspace
427
- // for that remote, only use the path as query
428
- // value to form shorter, nicer URLs.
429
- // ensure paths are absolute (begin with `/`)
430
- queryParamWorkspace = `${ posix . sep } ${ ltrim ( workspace . workspaceUri . path , posix . sep ) } ` ;
431
- } else {
432
- queryParamWorkspace = encodeURIComponent ( workspace . workspaceUri . toString ( true ) ) ;
433
- }
434
-
413
+ const queryParamWorkspace = this . encodeWorkspacePath ( workspace . workspaceUri ) ;
435
414
targetHref = `${ document . location . origin } ${ document . location . pathname } ?${ WorkspaceProvider . QUERY_PARAM_WORKSPACE } =${ queryParamWorkspace } ` ;
436
415
}
437
416
@@ -443,6 +422,22 @@ class WorkspaceProvider implements IWorkspaceProvider {
443
422
return targetHref ;
444
423
}
445
424
425
+ private encodeWorkspacePath ( uri : URI ) : string {
426
+ if ( this . config . remoteAuthority && uri . scheme === Schemas . vscodeRemote ) {
427
+
428
+ // when connected to a remote and having a folder
429
+ // or workspace for that remote, only use the path
430
+ // as query value to form shorter, nicer URLs.
431
+ // however, we still need to `encodeURIComponent`
432
+ // to ensure to preserve special characters, such
433
+ // as `+` in the path.
434
+
435
+ return encodeURIComponent ( `${ posix . sep } ${ ltrim ( uri . path , posix . sep ) } ` ) . replaceAll ( '%2F' , '/' ) ;
436
+ }
437
+
438
+ return encodeURIComponent ( uri . toString ( true ) ) ;
439
+ }
440
+
446
441
private isSame ( workspaceA : IWorkspace , workspaceB : IWorkspace ) : boolean {
447
442
if ( ! workspaceA || ! workspaceB ) {
448
443
return workspaceA === workspaceB ; // both empty
0 commit comments