Skip to content

Commit

Permalink
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.

Fixes: chocolatey#2345
  • Loading branch information
blami authored Apr 12, 2023
1 parent 370e366 commit 14f7145
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,45 +337,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 14f7145

Please sign in to comment.