-
Notifications
You must be signed in to change notification settings - Fork 903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(#2345) Avoid any trailing spaces after silentArgs #3113
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for getting this fixed up @blami. I've taken the liberty of adding a Pester test to this PR, rebased off of develop, then force pushed the change up to your fork. As I've added the Pester tests, I've asked for a review from @gep13 as well.
@gep13: The new Pester tests will fail in Test Kitchen as I have not yet pushed the package to the repositories used by Test Kitchen. Once the PR is merged I'll get those other repositories updated.
674686e
to
2d18385
Compare
@blami I've been trying to come up with a manual test to show that this fixes a broken package installation. Unfortunately, I haven't been able to find a version of TotalCommander on the Chocolatey Community Repository that exhibits this behaviour. Do you have a package available that I could use to demonstrate that this fix resolves the issue with that package? The pester tests I added show that the space is gone, but having another verification would be very helpful. |
@corbob Thanks a lot for picking up this! I just looked at Total Commander package in community and it should be still broken. This bug only surfaces if you set install location parameter. I cannot share our private repo but package excerpt that requires the fix is roughly: $ErrorActionPreference = 'Stop' # stop on all errors
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$url = 'https://totalcommander.ch/1052/tcmd1052x64.exe'
$packageArgs = @{
packageName = $env:ChocolateyPackageName
unzipLocation = $toolsDir
fileType = 'EXE'
url = $url
softwareName = 'Total Commander*'
# https://www.ghisler.ch/wiki/index.php?title=Installer#Description_of_switches_and_parameters
silentArgs = '/A1H1M0G1D0FN"*" U:\Program Files\TotalCmd'
validExitCodes= @(0)
}
Install-ChocolateyPackage @packageArgs Hope this helps. |
@blami Thank you for that script. I was able to reproduce the issue, and confirm that the updates made here resolve the issue. For completeness, my reproduction/verification steps:
Screenshot of the Chocolatey 2.2.2 behaviour: |
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.
This adds a set of tests to validate that the spaces that may be passed in by the package are honoured, while not introducing erroneous spaces.
During pairing with gep13, discovered that some of the Pester tests failed in Team City as they are likely waiting for the user to confirm running the PowerShell scripts as the certificate used to sign choco.exe differs from the ps1 files on development builds. This updates the tests to trust the certificate of the ps1 files as well so that the prompt doesn't happen.
Enhance the local testing process for developers. Instead of building all nuspec files we find, filter out ones that may have been built as part of previous tests. Update the vagrantfile to copy over changed files when running the test provisioner, but only purge the tests directory. Update the vagrantfile to set a hostname on the VM to prevent on-screen error messages that don't seem to affect anything.
As part of the recent renewal of the Chocolatey Certificate, the Subject name changed, so capturing the change here as another possible signature to check for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description Of Changes
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.
Motivation and Context
I have some installers doing similar thing as Total Commander (mentioned in #2345 ) - passing installation destination as last positional argument allowing spaces in it. Added trailing space caused by
"$silentArgs $additionalInstallArgs"
when$additionalInstallArgs
is empty breaks this mechanism and attempts to install to path that ends with space.NOTE: I am just an ordinary PowerShell user and not really skilled in it so any input on how to get this thing done is welcome. Also wasn't sure if its worth to apply this beyond
EXE
type asMSI
has its own way of passing arguments. Motivation to fix all types is mostly uniformity.Testing
Change Types Made
Change Checklist
Related Issue
Fixes: #2345