File tree Expand file tree Collapse file tree
packages/client-runtime/src/work-log Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ describe("commandProgramName", () => {
2323 [ "pwsh -NoProfile -Command Start-Process -FilePath git" , "git" ] ,
2424 [ 'powershell -Command "git;pwd" > out.txt' , "git" ] ,
2525 [ 'cmd /c "git&&npm test" 2>&1' , "git" ] ,
26+ [ "pwsh -Command '& Get-Date; Get-Location'" , "Get-Date" ] ,
27+ [ "pwsh -Command '& git|Out-Null'" , "git" ] ,
28+ [ "pwsh -Command '& “./build;release.ps1”'" , "build;release.ps1”" ] ,
2629 ] ) ( "unwraps shell scripts without executing them: %s" , ( command , program ) => {
2730 expect ( commandProgramName ( command ) ) . toBe ( program ) ;
2831 } ) ;
Original file line number Diff line number Diff line change @@ -933,7 +933,13 @@ function staticProgramName(value: string): string | null {
933933function leadingPowerShellLiteral ( command : string ) : string | null {
934934 const input = command . trimStart ( ) ;
935935 const quote = input [ 0 ] ;
936- if ( quote !== '"' && quote !== "'" ) return staticProgramName ( input . match ( / ^ \S + / u) ?. [ 0 ] ?? "" ) ;
936+ if ( quote !== '"' && quote !== "'" ) {
937+ const token = input . match ( / ^ \S + / u) ?. [ 0 ] ?? "" ;
938+ // Quotes (including PowerShell's typographic ones), escapes and subexpressions
939+ // can hide a delimiter, so only cut at a delimiter that comes before any of them.
940+ const stop = token . match ( / [ ; | & ' " ` $ ( { ‘ ’ ‚ ‛ “ ” „ ] / u) ;
941+ return staticProgramName ( stop && / [ ; | & ] / u. test ( stop [ 0 ] ) ? token . slice ( 0 , stop . index ) : token ) ;
942+ }
937943
938944 let value = "" ;
939945 for ( let index = 1 ; index < input . length ; index += 1 ) {
You can’t perform that action at this time.
0 commit comments