Skip to content

Commit d10bd8d

Browse files
chawyehsuniheaven
andauthored
fix(core): Fix Invoke-ExternalCommand regression (#5923)
Co-authored-by: Hsiao-nan Cheung <[email protected]>
1 parent 105e416 commit d10bd8d

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [Unreleased](https://github.com/ScoopInstaller/Scoop/compare/master...develop)
2+
3+
### Bug Fixes
4+
5+
- **core:** Fix `Invoke-ExternalCommand` regression ([#5923](https://github.com/ScoopInstaller/Scoop/issues/5923))
6+
17
## [v0.4.0](https://github.com/ScoopInstaller/Scoop/compare/v0.3.1...v0.4.0) - 2024-04-18
28

39
### Features

lib/core.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,14 @@ function Invoke-ExternalCommand {
747747
}
748748
if ($ArgumentList.Length -gt 0) {
749749
$ArgumentList = $ArgumentList | ForEach-Object { [regex]::Split($_.Replace('"', ''), '(?<=(?<![:\w])[/-]\w+) | (?=[/-])') }
750-
if ($FilePath -match '^((cmd|cscript|wscript|msiexec)(\.exe)?|.*\.(bat|cmd|js|vbs|wsf))$') {
751-
$Process.StartInfo.Arguments = $ArgumentList -join ' '
752-
} elseif ($Process.StartInfo.ArgumentList.Add) {
750+
# Use legacy argument escaping for commands having non-standard behavior
751+
# with regard to argument passing. `msiexec` requires some args like
752+
# `TARGETDIR="C:\Program Files"`, which is non-standard, therefore we
753+
# treat it as a legacy command.
754+
# ref-1: https://learn.microsoft.com/en-us/powershell/scripting/learn/experimental-features?view=powershell-7.4#psnativecommandargumentpassing
755+
$LegacyCommand = $FilePath -match '^((cmd|cscript|find|sqlcmd|wscript|msiexec)(\.exe)?|.*\.(bat|cmd|js|vbs|wsf))$'
756+
$SupportArgumentList = $Process.StartInfo.PSObject.Properties.Name -contains 'ArgumentList'
757+
if ((-not $LegacyCommand) -and $SupportArgumentList) {
753758
# ArgumentList is supported in PowerShell 6.1 and later (built on .NET Core 2.1+)
754759
# ref-1: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.argumentlist?view=net-6.0
755760
# ref-2: https://docs.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.2#net-framework-vs-net-core

test/Scoop-Decompress.Tests.ps1

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,46 @@ Describe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' {
158158
} elseif (!(installed lessmsi)) {
159159
scoop install lessmsi
160160
}
161+
Copy-Item "$working_dir\MSITest.msi" "$working_dir\MSI Test.msi"
161162
$test1 = "$working_dir\MSITest.msi"
162-
$test2 = "$working_dir\MSITestNull.msi"
163+
$test2 = "$working_dir\MSI Test.msi"
164+
$test3 = "$working_dir\MSITestNull.msi"
163165
}
164166

165-
It 'extract normal MSI file' {
167+
It 'extract normal MSI file using msiexec' {
166168
Mock get_config { $false }
167169
$to = test_extract 'Expand-MsiArchive' $test1
168170
$to | Should -Exist
169171
"$to\MSITest\empty" | Should -Exist
170172
(Get-ChildItem "$to\MSITest").Count | Should -Be 1
171173
}
172174

173-
It 'extract empty MSI file using lessmsi' {
175+
It 'extract normal MSI file with whitespace in path using msiexec' {
176+
Mock get_config { $false }
177+
$to = test_extract 'Expand-MsiArchive' $test2
178+
$to | Should -Exist
179+
"$to\MSITest\empty" | Should -Exist
180+
(Get-ChildItem "$to\MSITest").Count | Should -Be 1
181+
}
182+
183+
It 'extract normal MSI file using lessmsi' {
184+
Mock get_config { $true }
185+
$to = test_extract 'Expand-MsiArchive' $test1
186+
$to | Should -Exist
187+
}
188+
189+
It 'extract normal MSI file with whitespace in path using lessmsi' {
174190
Mock get_config { $true }
175191
$to = test_extract 'Expand-MsiArchive' $test2
176192
$to | Should -Exist
177193
}
178194

195+
It 'extract empty MSI file using lessmsi' {
196+
Mock get_config { $true }
197+
$to = test_extract 'Expand-MsiArchive' $test3
198+
$to | Should -Exist
199+
}
200+
179201
It 'works with "-Removal" switch ($removal param)' {
180202
Mock get_config { $false }
181203
$test1 | Should -Exist

0 commit comments

Comments
 (0)