Skip to content

Commit

Permalink
fix(iec): Fix arguments parsing method of Invoke-ExternalCommand()
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven committed Mar 21, 2024
1 parent 90766f9 commit 76fe8f9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ function Invoke-ExternalCommand {
$Process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
}
if ($ArgumentList.Length -gt 0) {
$ArgumentList = $ArgumentList | ForEach-Object { [regex]::Split($_.Replace('"', ''), '(?<=(?<![:\w])[/-][^\\/ ]+) | (?=[/-])') }
if ($FilePath -match '^((cmd|cscript|wscript|msiexec)(\.exe)?|.*\.(bat|cmd|js|vbs|wsf))$') {
$Process.StartInfo.Arguments = $ArgumentList -join ' '
} elseif ($Process.StartInfo.ArgumentList.Add) {
Expand All @@ -665,10 +666,12 @@ function Invoke-ExternalCommand {
$s = $_ -replace '(\\+)"', '$1$1"'
# escape N consecutive backslash(es), which are at the end of the string, to 2N consecutive ones
$s = $s -replace '(\\+)$', '$1$1'
# escape double quotes
$s = $s -replace '"', '\"'
# quote the argument
"`"$s`""
if ($s -match ' ') {
"`"$s`""
} else {
$s
}
}
$Process.StartInfo.Arguments = $escapedArgs -join ' '
}
Expand Down

0 comments on commit 76fe8f9

Please sign in to comment.