Skip to content

Commit 0ed5431

Browse files
authored
Fix crash of PSES on startup (and debug startup) when workspace folder has wildard chars [] in path (PowerShell#580)
1 parent 68d4096 commit 0ed5431

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ protected async Task HandleLaunchRequest(
294294
if (this.editorSession.PowerShellContext.CurrentRunspace.Location == RunspaceLocation.Local &&
295295
!this.editorSession.DebugService.IsDebuggerStopped)
296296
{
297-
await editorSession.PowerShellContext.SetWorkingDirectory(workingDir);
297+
await editorSession.PowerShellContext.SetWorkingDirectory(workingDir, isPathAlreadyEscaped: false);
298298
Logger.Write(LogLevel.Verbose, "Working dir set to: " + workingDir);
299299
}
300300

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ protected async Task HandleInitializeRequest(
178178
if (editorSession.Workspace.WorkspacePath != null)
179179
{
180180
await editorSession.PowerShellContext.SetWorkingDirectory(
181-
editorSession.Workspace.WorkspacePath);
181+
editorSession.Workspace.WorkspacePath,
182+
isPathAlreadyEscaped: false);
182183
}
183184

184185
await requestContext.SendResult(

src/PowerShellEditorServices/Session/PowerShellContext.cs

+15
Original file line numberDiff line numberDiff line change
@@ -1078,11 +1078,26 @@ internal void ReleaseRunspaceHandle(RunspaceHandle runspaceHandle)
10781078
/// </summary>
10791079
/// <param name="path"></param>
10801080
public async Task SetWorkingDirectory(string path)
1081+
{
1082+
await this.SetWorkingDirectory(path, true);
1083+
}
1084+
1085+
/// <summary>
1086+
/// Sets the current working directory of the powershell context.
1087+
/// </summary>
1088+
/// <param name="path"></param>
1089+
/// <param name="isPathAlreadyEscaped">Specify false to have the path escaped, otherwise specify true if the path has already been escaped.</param>
1090+
public async Task SetWorkingDirectory(string path, bool isPathAlreadyEscaped)
10811091
{
10821092
this.InitialWorkingDirectory = path;
10831093

10841094
using (RunspaceHandle runspaceHandle = await this.GetRunspaceHandle())
10851095
{
1096+
if (!isPathAlreadyEscaped)
1097+
{
1098+
path = EscapePath(path, false);
1099+
}
1100+
10861101
runspaceHandle.Runspace.SessionStateProxy.Path.SetLocation(path);
10871102
}
10881103
}

0 commit comments

Comments
 (0)