Skip to content

Fix Windows argument quoting - #139

Closed
rsgalloway wants to merge 1 commit into
masterfrom
issue138/windows-argument-quoting
Closed

rsgalloway wants to merge 1 commit into
masterfrom
issue138/windows-argument-quoting

Conversation

@rsgalloway

Copy link
Copy Markdown
Owner

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:

  • Refactored CmdWrapper in lib/envstack/wrapper.py to use subprocess.list2cmdline for Windows-native quoting and to construct the command string with /s /c to preserve quoted arguments, especially after --. This fixes issues with PowerShell script paths containing spaces.
  • Updated get_subprocess_command to return the correctly quoted command string instead of an argv list, aligning with Windows command invocation expectations.
  • Adjusted logic to recognize both cmd and cmd.exe as valid shell names, improving compatibility.

Testing enhancements:

  • Added new tests in tests/test_wrapper.py to 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:

  • Updated CHANGELOG.md to document the fix for preserving Windows command argument quoting after --, including PowerShell script paths with spaces.

@rsgalloway rsgalloway self-assigned this Sep 15, 2026
@rsgalloway rsgalloway added the bug Something isn't working label Sep 15, 2026
@rsgalloway
rsgalloway requested a lite review from Copilot September 15, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.list2cmdline with cmd /s /c.
  • Supports both cmd and cmd.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.exe handling only to run_command, but capture_output() still checks shellname in ["cmd"] at wrapper.py:273. With config.SHELL == "cmd.exe", command substitutions go through POSIX shlex.split, which removes or mangles Windows backslashes in paths before subprocess.run; evaluate_command() uses this path. Update the corresponding capture_output() dispatch and add a regression test for the cmd.exe name.
    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.

Comment thread lib/envstack/wrapper.py
# 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)
@rsgalloway

Copy link
Copy Markdown
Owner Author

closing this as the wrong approach for this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants