From da2d9f0944d19908b8d0848844fe615d164c02ef Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Tue, 2 Feb 2016 18:08:31 -0700 Subject: [PATCH 1/2] Fix for issue #123, wildcard chars in script path prevent breakpoints from working. Once I got breakpoints to be able to set for files like foo[1].ps1 and foo][.ps1 I noticed that the script named foo][.ps1 would not execute at all!! You get an error saying something like the specified wildcard character pattern is not valid. FWIW ISE fails with this same message. So PSES has one up on ISE. :-) --- .../Debugging/DebugService.cs | 16 +++++++++++++++- .../Session/PowerShellContext.cs | 7 ++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices/Debugging/DebugService.cs b/src/PowerShellEditorServices/Debugging/DebugService.cs index 30cc409cd..5e8a43d02 100644 --- a/src/PowerShellEditorServices/Debugging/DebugService.cs +++ b/src/PowerShellEditorServices/Debugging/DebugService.cs @@ -56,6 +56,16 @@ public DebugService(PowerShellContext powerShellContext) #region Public Methods + /// + /// Returns the passed in path with the [ and ] wildcard characters escaped. + /// + /// The path to process. + /// The path with [ and ] escaped. + public static string EscapeWilcardsInPath(string path) + { + return path.Replace("[", "`[").Replace("]", "`]"); + } + /// /// Sets the list of breakpoints for the current debugging session. /// @@ -77,9 +87,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 = EscapeWilcardsInPath(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..4dbd94735 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 = DebugService.EscapeWilcardsInPath(scriptPath); + PSCommand command = new PSCommand(); - command.AddCommand(scriptPath); + command.AddCommand(escapedScriptPath); await this.ExecuteCommand(command, true); } From 48db084d773b2af6596183df589c7512b5cd54b4 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Tue, 2 Feb 2016 18:25:48 -0700 Subject: [PATCH 2/2] Fixed typo in EscapedWilcardsInPath and moved static method to PowerShellContext. --- .../Debugging/DebugService.cs | 12 +----------- .../Session/PowerShellContext.cs | 12 +++++++++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/PowerShellEditorServices/Debugging/DebugService.cs b/src/PowerShellEditorServices/Debugging/DebugService.cs index 5e8a43d02..55120e7a3 100644 --- a/src/PowerShellEditorServices/Debugging/DebugService.cs +++ b/src/PowerShellEditorServices/Debugging/DebugService.cs @@ -56,16 +56,6 @@ public DebugService(PowerShellContext powerShellContext) #region Public Methods - /// - /// Returns the passed in path with the [ and ] wildcard characters escaped. - /// - /// The path to process. - /// The path with [ and ] escaped. - public static string EscapeWilcardsInPath(string path) - { - return path.Replace("[", "`[").Replace("]", "`]"); - } - /// /// Sets the list of breakpoints for the current debugging session. /// @@ -89,7 +79,7 @@ public async Task SetBreakpoints( { // Fix for issue #123 - file paths that contain wildcard chars [ and ] need to // quoted and have those wildcard chars escaped. - string escapedScriptPath = EscapeWilcardsInPath(scriptFile.FilePath); + string escapedScriptPath = PowerShellContext.EscapeWildcardsInPath(scriptFile.FilePath); PSCommand psCommand = new PSCommand(); psCommand.AddCommand("Set-PSBreakpoint"); diff --git a/src/PowerShellEditorServices/Session/PowerShellContext.cs b/src/PowerShellEditorServices/Session/PowerShellContext.cs index 4dbd94735..2d1ebf336 100644 --- a/src/PowerShellEditorServices/Session/PowerShellContext.cs +++ b/src/PowerShellEditorServices/Session/PowerShellContext.cs @@ -438,7 +438,7 @@ 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 = DebugService.EscapeWilcardsInPath(scriptPath); + string escapedScriptPath = EscapeWildcardsInPath(scriptPath); PSCommand command = new PSCommand(); command.AddCommand(escapedScriptPath); @@ -552,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