diff --git a/src/PowerShellEditorServices/Debugging/DebugService.cs b/src/PowerShellEditorServices/Debugging/DebugService.cs index 30cc409cd..55120e7a3 100644 --- a/src/PowerShellEditorServices/Debugging/DebugService.cs +++ b/src/PowerShellEditorServices/Debugging/DebugService.cs @@ -77,9 +77,13 @@ public async Task SetBreakpoints( if (lineNumbers.Length > 0) { + // Fix for issue #123 - file paths that contain wildcard chars [ and ] need to + // quoted and have those wildcard chars escaped. + string escapedScriptPath = PowerShellContext.EscapeWildcardsInPath(scriptFile.FilePath); + PSCommand psCommand = new PSCommand(); psCommand.AddCommand("Set-PSBreakpoint"); - psCommand.AddParameter("Script", scriptFile.FilePath); + psCommand.AddParameter("Script", escapedScriptPath); psCommand.AddParameter("Line", lineNumbers.Length > 0 ? lineNumbers : null); resultBreakpoints = diff --git a/src/PowerShellEditorServices/Session/PowerShellContext.cs b/src/PowerShellEditorServices/Session/PowerShellContext.cs index 4690e585a..2d1ebf336 100644 --- a/src/PowerShellEditorServices/Session/PowerShellContext.cs +++ b/src/PowerShellEditorServices/Session/PowerShellContext.cs @@ -435,8 +435,13 @@ public async Task> ExecuteScriptString( /// A Task that can be awaited for completion. public async Task ExecuteScriptAtPath(string scriptPath) { + // If we don't escape wildcard characters in the script path, the script can + // fail to execute if say the script name was foo][.ps1. + // Related to issue #123. + string escapedScriptPath = EscapeWildcardsInPath(scriptPath); + PSCommand command = new PSCommand(); - command.AddCommand(scriptPath); + command.AddCommand(escapedScriptPath); await this.ExecuteCommand(command, true); } @@ -547,6 +552,16 @@ internal void ReleaseRunspaceHandle(RunspaceHandle runspaceHandle) } } + /// + /// Returns the passed in path with the [ and ] wildcard characters escaped. + /// + /// The path to process. + /// The path with [ and ] escaped. + internal static string EscapeWildcardsInPath(string path) + { + return path.Replace("[", "`[").Replace("]", "`]"); + } + #endregion #region Events