Skip to content

Fix for issue #123, wildcard chars in script path prevent breakpoints… #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/PowerShellEditorServices/Debugging/DebugService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,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 = 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 =
Expand Down
17 changes: 16 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 = EscapeWildcardsInPath(scriptPath);

PSCommand command = new PSCommand();
command.AddCommand(scriptPath);
command.AddCommand(escapedScriptPath);

await this.ExecuteCommand<object>(command, true);
}
Expand Down Expand Up @@ -547,6 +552,16 @@ internal void ReleaseRunspaceHandle(RunspaceHandle runspaceHandle)
}
}

/// <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>
internal static string EscapeWildcardsInPath(string path)
{
return path.Replace("[", "`[").Replace("]", "`]");
}

#endregion

#region Events
Expand Down