Skip to content

Commit da2d9f0

Browse files
committed
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. :-)
1 parent 2fcd1e0 commit da2d9f0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/PowerShellEditorServices/Debugging/DebugService.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ public DebugService(PowerShellContext powerShellContext)
5656

5757
#region Public Methods
5858

59+
/// <summary>
60+
/// Returns the passed in path with the [ and ] wildcard characters escaped.
61+
/// </summary>
62+
/// <param name="path">The path to process.</param>
63+
/// <returns>The path with [ and ] escaped.</returns>
64+
public static string EscapeWilcardsInPath(string path)
65+
{
66+
return path.Replace("[", "`[").Replace("]", "`]");
67+
}
68+
5969
/// <summary>
6070
/// Sets the list of breakpoints for the current debugging session.
6171
/// </summary>
@@ -77,9 +87,13 @@ public async Task<BreakpointDetails[]> SetBreakpoints(
7787

7888
if (lineNumbers.Length > 0)
7989
{
90+
// Fix for issue #123 - file paths that contain wildcard chars [ and ] need to
91+
// quoted and have those wildcard chars escaped.
92+
string escapedScriptPath = EscapeWilcardsInPath(scriptFile.FilePath);
93+
8094
PSCommand psCommand = new PSCommand();
8195
psCommand.AddCommand("Set-PSBreakpoint");
82-
psCommand.AddParameter("Script", scriptFile.FilePath);
96+
psCommand.AddParameter("Script", escapedScriptPath);
8397
psCommand.AddParameter("Line", lineNumbers.Length > 0 ? lineNumbers : null);
8498

8599
resultBreakpoints =

src/PowerShellEditorServices/Session/PowerShellContext.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,13 @@ public async Task<IEnumerable<object>> ExecuteScriptString(
435435
/// <returns>A Task that can be awaited for completion.</returns>
436436
public async Task ExecuteScriptAtPath(string scriptPath)
437437
{
438+
// If we don't escape wildcard characters in the script path, the script can
439+
// fail to execute if say the script name was foo][.ps1.
440+
// Related to issue #123.
441+
string escapedScriptPath = DebugService.EscapeWilcardsInPath(scriptPath);
442+
438443
PSCommand command = new PSCommand();
439-
command.AddCommand(scriptPath);
444+
command.AddCommand(escapedScriptPath);
440445

441446
await this.ExecuteCommand<object>(command, true);
442447
}

0 commit comments

Comments
 (0)