From f41eaeede891d8ecc88e97174f7c4edc615416c1 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Fri, 24 Nov 2017 13:27:41 -0700 Subject: [PATCH] Fix crash of PSES on startup (and debug startup) when workspace folder has wildard chars [] in path --- .../Server/DebugAdapter.cs | 2 +- .../Server/LanguageServer.cs | 3 ++- .../Session/PowerShellContext.cs | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs index 0b50dca3b..115d3ca44 100644 --- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs +++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs @@ -294,7 +294,7 @@ protected async Task HandleLaunchRequest( if (this.editorSession.PowerShellContext.CurrentRunspace.Location == RunspaceLocation.Local && !this.editorSession.DebugService.IsDebuggerStopped) { - await editorSession.PowerShellContext.SetWorkingDirectory(workingDir); + await editorSession.PowerShellContext.SetWorkingDirectory(workingDir, isPathAlreadyEscaped: false); Logger.Write(LogLevel.Verbose, "Working dir set to: " + workingDir); } diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 8e157be92..6b2413ea8 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -178,7 +178,8 @@ protected async Task HandleInitializeRequest( if (editorSession.Workspace.WorkspacePath != null) { await editorSession.PowerShellContext.SetWorkingDirectory( - editorSession.Workspace.WorkspacePath); + editorSession.Workspace.WorkspacePath, + isPathAlreadyEscaped: false); } await requestContext.SendResult( diff --git a/src/PowerShellEditorServices/Session/PowerShellContext.cs b/src/PowerShellEditorServices/Session/PowerShellContext.cs index 0c6e1ee98..51cd79d64 100644 --- a/src/PowerShellEditorServices/Session/PowerShellContext.cs +++ b/src/PowerShellEditorServices/Session/PowerShellContext.cs @@ -1078,11 +1078,26 @@ internal void ReleaseRunspaceHandle(RunspaceHandle runspaceHandle) /// /// public async Task SetWorkingDirectory(string path) + { + await this.SetWorkingDirectory(path, true); + } + + /// + /// Sets the current working directory of the powershell context. + /// + /// + /// Specify false to have the path escaped, otherwise specify true if the path has already been escaped. + public async Task SetWorkingDirectory(string path, bool isPathAlreadyEscaped) { this.InitialWorkingDirectory = path; using (RunspaceHandle runspaceHandle = await this.GetRunspaceHandle()) { + if (!isPathAlreadyEscaped) + { + path = EscapePath(path, false); + } + runspaceHandle.Runspace.SessionStateProxy.Path.SetLocation(path); } }