File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
src/PowerShellEditorServices Expand file tree Collapse file tree 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(
7777
7878 if ( lineNumbers . Length > 0 )
7979 {
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+
8084 PSCommand psCommand = new PSCommand ( ) ;
8185 psCommand . AddCommand ( "Set-PSBreakpoint" ) ;
82- psCommand . AddParameter ( "Script" , scriptFile . FilePath ) ;
86+ psCommand . AddParameter ( "Script" , escapedScriptPath ) ;
8387 psCommand . AddParameter ( "Line" , lineNumbers . Length > 0 ? lineNumbers : null ) ;
8488
8589 resultBreakpoints =
Original file line number Diff line number Diff 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 = EscapeWildcardsInPath ( scriptPath ) ;
442+
438443 PSCommand command = new PSCommand ( ) ;
439- command . AddCommand ( scriptPath ) ;
444+ command . AddCommand ( escapedScriptPath ) ;
440445
441446 await this . ExecuteCommand < object > ( command , true ) ;
442447 }
@@ -547,6 +552,16 @@ internal void ReleaseRunspaceHandle(RunspaceHandle runspaceHandle)
547552 }
548553 }
549554
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+
550565 #endregion
551566
552567 #region Events
You can’t perform that action at this time.
0 commit comments