Skip to content

Conversation

AdmiringWorm
Copy link
Member

@AdmiringWorm AdmiringWorm commented Jun 17, 2025

Description Of Changes

  • Escape single quotes in PowerShell arguments by doubling them to handle parameters containing single quotes correctly; added Pester tests for validation.
  • Refactor argument parsing to properly handle package arguments with double-dash syntax (--), including quoted strings and nested quotes; added tests for upgrade scenarios.
  • Add warnings for unbalanced single or double quotes in package arguments during install, upgrade, and uninstall commands, with troubleshooting advice for upgrades and uninstalls; included tests for warning behavior with remembered arguments.

Motivation and Context

Packages should be possible to install and upgrade even with single quotes being used, and not having an exception about "unterminated single quotes" being thrown.

Testing

  1. Enable the feature useRememberedArgumentsForUpgrades using choco feature enable -n useRememberedArgumentsForUpgrades.
  2. Install the test-params package using choco install test-params --package-parameters="/Comment:It's great! /SubmittedBy:Someone".
  3. Verify package installed correctly, and it outputted a warning for the environment variable: "WARNING: - Comment = It's great!.
  4. Verify parameters show up when calling info using choco info test-params --local-only.
  5. Verify the full package-parameters line is not cut off.
  6. Install the test-environment package using choco install test-environment --package-parameters="'--quiet --norestart --wait --includeRecommended --includeOptional'" --verbose --version 0.9.
  7. Ensure it was installed successfully.
  8. Verify teh package parameters are outputted correctly using choco info test-environment --local-only (to partial package-parameter lines)
  9. Attempt to ugrade the package using choco upgrade test-environment.
  10. Verify the package was updated successfully.
  11. Verify the package outputted chocolateyPackageParameters=--quiet --norestart --wait --includeRecommended --includeOptional

Operating Systems Testing

  • Windows 11

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

@AdmiringWorm AdmiringWorm requested a review from gep13 June 17, 2025 11:11
@AdmiringWorm AdmiringWorm force-pushed the improve-argument-parsing-fix-quotes branch 2 times, most recently from 81d4af1 to b92bacf Compare June 17, 2025 12:09
Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of quick questions/comments, otherwise this looks really good!

…d tests

Update EscapePowerShellArguments to also replace single quotes with
two single quotes to properly handle parameters containing single quotes.

Add Pester tests for 'choco install' and 'choco info' commands to verify
correct handling and output of package parameters with single quotes.

These changes improve robustness when passing parameters with single
quotes to PowerShell scripts and ensure expected behavior is tested.

Based on code in PR: chocolatey#2804
…sh syntax

Refactor argument splitting logic to correctly handle package arguments
that use double-dash prefixes (--). The new SplitOnArguments method
handles quoted strings, escaped characters, and nested quotes to ensure
accurate parsing of complex argument strings.

Add a Pester test to verify upgrading a package with double-dash package
parameters works as expected, including environment variable setting and
successful upgrade reporting.

These changes fix issues with parsing package parameters during upgrades
and improve reliability when using advanced argument formats.
…upgrades

Add detection of unbalanced single or double quotes in package arguments
during install, upgrade, and uninstall commands. Emit warnings to alert
users that failures may be related to these potentially problematic
arguments. For upgrades and uninstalls, include troubleshooting advice
to run `choco info` with local-only flag.

Add a test verifying upgrade behavior when package parameters contain
single quotes and remembered arguments are enabled, ensuring warnings
and diagnostic messages appear as expected.

NOTE: Install and uninstall warnings and diagnostics are for future
implementations, and will not be shown during normal execution today.
@AdmiringWorm AdmiringWorm force-pushed the improve-argument-parsing-fix-quotes branch from b92bacf to f5bf086 Compare June 18, 2025 08:18
@AdmiringWorm AdmiringWorm requested a review from gep13 June 18, 2025 08:20
Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@gep13 gep13 merged commit dafbf77 into chocolatey:develop Jun 18, 2025
5 checks passed
@gep13
Copy link
Member

gep13 commented Jun 18, 2025

@AdmiringWorm thanks for getting this fixed!

@AdmiringWorm AdmiringWorm deleted the improve-argument-parsing-fix-quotes branch July 4, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

choco upgrade command fails with error message The string is missing the terminator: '. when useRememberedArgumentsForUpgrades feature is enabled
2 participants