Fix Windows argument quoting - #139
Closed
rsgalloway wants to merge 1 commit into
Closed
rsgalloway wants to merge 1 commit into
rsgalloway wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
cmd.exe metacharacters remain unescaped, so valid arguments can still be parsed incorrectly.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Improves Windows command argument quoting, especially for PowerShell paths with spaces and arguments after --.
Changes:
- Uses
subprocess.list2cmdlinewithcmd /s /c. - Supports both
cmdandcmd.exe. - Adds regression tests and changelog documentation.
File summaries
| File | Summary |
|---|---|
tests/test_wrapper.py |
Adds Windows quoting and argument round-trip tests. |
lib/envstack/wrapper.py |
Updates command construction and shell detection; moderate issue remains because cmd.exe metacharacters are not escaped (3 votes), including line 333. |
CHANGELOG.md |
Documents the Windows quoting fix. |
Review details
Suppressed comments (1)
lib/envstack/wrapper.py:333
- This adds
cmd.exehandling only torun_command, butcapture_output()still checksshellname in ["cmd"]at wrapper.py:273. Withconfig.SHELL == "cmd.exe", command substitutions go through POSIXshlex.split, which removes or mangles Windows backslashes in paths beforesubprocess.run;evaluate_command()uses this path. Update the correspondingcapture_output()dispatch and add a regression test for thecmd.exename.
if shellname in ["cmd", "cmd.exe"]:
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # cmd.exe /c <command> | ||
| self._subprocess_argv = [self._cmd_exe, "/c", cmdline] | ||
| # Preserve argv boundaries using Windows quoting, not POSIX shlex. | ||
| cmdline = subprocess.list2cmdline(self.cmd) |
Owner
Author
|
closing this as the wrong approach for this issue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Address #138
This pull request focuses on improving the handling of Windows command argument quoting, particularly for cases involving PowerShell script paths with spaces and proper preservation of argument boundaries after
--. The changes ensure that commands passed to Windows shells are quoted correctly, preventing issues with paths or arguments containing spaces or special characters. The update also adds comprehensive tests to verify this behavior across various scenarios.Windows command argument quoting improvements:
CmdWrapperinlib/envstack/wrapper.pyto usesubprocess.list2cmdlinefor Windows-native quoting and to construct the command string with/s /cto preserve quoted arguments, especially after--. This fixes issues with PowerShell script paths containing spaces.get_subprocess_commandto return the correctly quoted command string instead of an argv list, aligning with Windows command invocation expectations.cmdandcmd.exeas valid shell names, improving compatibility.Testing enhancements:
tests/test_wrapper.pyto verify correct quoting for PowerShell script paths with spaces, argument roundtrips, and quoting for executables and arguments on Windows. These tests ensure robust handling of edge cases and regression prevention.Changelog update:
CHANGELOG.mdto document the fix for preserving Windows command argument quoting after--, including PowerShell script paths with spaces.