Skip to content

Commit

Permalink
(chocolatey#2345) Avoid any trailing spaces after silentArgs
Browse files Browse the repository at this point in the history
Fix a bug where concatenating silentArgs and additionalInstallArgs adds
a trailing space at the end of silentArgs even when
additionalInstallArgs is empty. Such trailing space can change the
meaning of the last positional argument (that may contain spaces).

Final arguments are now created as space joined string arrays filtered
down to only non-empty items. Fix is applied to all installer types.

It is expected not to manipulate the arguments themselves in case there
are any spaces that the package maintainer has included.
  • Loading branch information
blami authored and corbob committed May 21, 2024
1 parent c2d64b1 commit 6acb630
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,45 +336,47 @@ Pro / Business supports a single, ubiquitous install directory option.
$msiArgs = "/i `"$fileFullPath`""
$msiArgs = if ($overrideArguments) {
Write-Host "Overriding package arguments with '$additionalInstallArgs' (replacing '$silentArgs')"
"$msiArgs $additionalInstallArgs"
(($msiArgs, $additionalInstallArgs) | Where-Object { $_ }) -join " "
}
else {
"$msiArgs $silentArgs $additionalInstallArgs"
(($msiArgs, $silentArgs, $additionalInstallArgs) | Where-Object { $_ }) -join " "
}

$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$msiArgs" "$($env:SystemRoot)\System32\msiexec.exe" -validExitCodes $validExitCodes -workingDirectory $workingDirectory
}

if ($fileType -like 'msp') {
$msiArgs = '/update "{0}"' -f $fileFullPath
if ($overrideArguments) {
$msiArgs = if ($overrideArguments) {
Write-Host "Overriding package arguments with '$additionalInstallArgs' (replacing '$silentArgs')";
$msiArgs = "$msiArgs $additionalInstallArgs";
(($msiArgs, $additionalInstallArgs) | Where-Object { $_ }) -join " "
}
else {
$msiArgs = "$msiArgs $silentArgs $additionalInstallArgs";
(($msiArgs, $silentArgs, $additionalInstallArgs) | Where-Object { $_ }) -join " "
}

$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$msiArgs" "$($env:SystemRoot)\System32\msiexec.exe" -validExitCodes $validExitCodes -workingDirectory $workingDirectory
}

if ($fileType -like 'exe') {
if ($overrideArguments) {
$exeArgs = if ($overrideArguments) {
Write-Host "Overriding package arguments with '$additionalInstallArgs' (replacing '$silentArgs')";
$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$additionalInstallArgs" $fileFullPath -validExitCodes $validExitCodes -workingDirectory $workingDirectory
$additionalInstallArgs
}
else {
$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$silentArgs $additionalInstallArgs" $fileFullPath -validExitCodes $validExitCodes -workingDirectory $workingDirectory
(($silentArgs, $additionalInstallArgs) | Where-Object { $_ }) -join " "
}
$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$exeArgs" $fileFullPath -validExitCodes $validExitCodes -workingDirectory $workingDirectory
}

if ($fileType -like 'msu') {
if ($overrideArguments) {
$msuArgs = "`"$fileFullPath`""
$msuArgs = if ($overrideArguments) {
Write-Host "Overriding package arguments with '$additionalInstallArgs' (replacing '$silentArgs')";
$msuArgs = "`"$fileFullPath`" $additionalInstallArgs"
(($msuArgs, $additionalInstallArgs) | Where-Object { $_ }) -join " "
}
else {
$msuArgs = "`"$fileFullPath`" $silentArgs $additionalInstallArgs"
(($msuArgs, $silentArgs, $additionalInstallArgs) | Where-Object { $_ }) -join " "
}
$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$msuArgs" "$($env:SystemRoot)\System32\wusa.exe" -validExitCodes $validExitCodes -workingDirectory $workingDirectory
}
Expand Down

0 comments on commit 6acb630

Please sign in to comment.