Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/PowerShellEditorServices/Debugging/DebugService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public DebugService(PowerShellContext powerShellContext)

#region Public Methods

/// <summary>
/// Returns the passed in path with the [ and ] wildcard characters escaped.
/// </summary>
/// <param name="path">The path to process.</param>
/// <returns>The path with [ and ] escaped.</returns>
public static string EscapeWilcardsInPath(string path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but slight typo here: EscapeWildcardsInPath

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I'd say this method probably belongs in PowerShellContext rather than DebugService since it may have more general utility

{
return path.Replace("[", "`[").Replace("]", "`]");
}

/// <summary>
/// Sets the list of breakpoints for the current debugging session.
/// </summary>
Expand All @@ -77,9 +87,13 @@ public async Task<BreakpointDetails[]> 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 =
Expand Down
7 changes: 6 additions & 1 deletion src/PowerShellEditorServices/Session/PowerShellContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,13 @@ public async Task<IEnumerable<object>> ExecuteScriptString(
/// <returns>A Task that can be awaited for completion.</returns>
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<object>(command, true);
}
Expand Down