File tree 2 files changed +21
-2
lines changed
src/PowerShellEditorServices
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -77,9 +77,13 @@ public async Task<BreakpointDetails[]> SetBreakpoints(
77
77
78
78
if ( lineNumbers . Length > 0 )
79
79
{
80
+ // Fix for issue #123 - file paths that contain wildcard chars [ and ] need to
81
+ // quoted and have those wildcard chars escaped.
82
+ string escapedScriptPath = PowerShellContext . EscapeWildcardsInPath ( scriptFile . FilePath ) ;
83
+
80
84
PSCommand psCommand = new PSCommand ( ) ;
81
85
psCommand . AddCommand ( "Set-PSBreakpoint" ) ;
82
- psCommand . AddParameter ( "Script" , scriptFile . FilePath ) ;
86
+ psCommand . AddParameter ( "Script" , escapedScriptPath ) ;
83
87
psCommand . AddParameter ( "Line" , lineNumbers . Length > 0 ? lineNumbers : null ) ;
84
88
85
89
resultBreakpoints =
Original file line number Diff line number Diff line change @@ -435,8 +435,13 @@ public async Task<IEnumerable<object>> ExecuteScriptString(
435
435
/// <returns>A Task that can be awaited for completion.</returns>
436
436
public async Task ExecuteScriptAtPath ( string scriptPath )
437
437
{
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 = EscapeWildcardsInPath ( scriptPath ) ;
442
+
438
443
PSCommand command = new PSCommand ( ) ;
439
- command . AddCommand ( scriptPath ) ;
444
+ command . AddCommand ( escapedScriptPath ) ;
440
445
441
446
await this . ExecuteCommand < object > ( command , true ) ;
442
447
}
@@ -547,6 +552,16 @@ internal void ReleaseRunspaceHandle(RunspaceHandle runspaceHandle)
547
552
}
548
553
}
549
554
555
+ /// <summary>
556
+ /// Returns the passed in path with the [ and ] wildcard characters escaped.
557
+ /// </summary>
558
+ /// <param name="path">The path to process.</param>
559
+ /// <returns>The path with [ and ] escaped.</returns>
560
+ internal static string EscapeWildcardsInPath ( string path )
561
+ {
562
+ return path . Replace ( "[" , "`[" ) . Replace ( "]" , "`]" ) ;
563
+ }
564
+
550
565
#endregion
551
566
552
567
#region Events
You can’t perform that action at this time.
0 commit comments