Repository navigation
Pass Cmd() and Bash() commands through without mangling their quotes - #9
Merged
Merged
Conversation
Cmd() on Windows handed the command to cmd.exe as one argument, so it was escaped for argv parsing: every " became \". cmd.exe doesn't parse argv; it runs everything after /C as typed, so programs got literal \" and quoted arguments broke, along with any | & > inside them. Cmd() now gives cmd.exe the command line as-is: /S /C "<command>". Bash() escaped the command's quotes before Command.Run escaped the argument again, so bash saw \" (a literal quote) instead of quotes around an argument. It now passes the command as typed. Adds tests for quoted arguments with spaces and pipes, and bumps the version to 3.2.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Any
Cmd()orBash()command with a quoted argument broke. In Boxcars,Cmd("az webapp config appsettings list ... --query \"[?name=='X'].value | [0]\" -o tsv")failed with exit code 2.Cmd() on Windows
Cause: the command went to
cmd.exeas a single argument,Command.Run("cmd.exe", ["/Q", "/C", cmd]). MedallionShell escapes each argument for argv parsing, so every"became\". Butcmd.exedoesn't parse argv; it runs everything after/Cas typed. Programs therefore received literal\", and a|,&or>inside the quotes ended up outside them as far ascmd.exewas concerned.Cmd()echo "[a | b]"\"[a | b]\"echo [a ^| b][a | b]Fix:
Cmd()sets the raw command line itself,[/Q] /S /C "<cmd>", throughopt.StartInfo(...)./Smakescmd.exestrip exactly the outer pair of quotes and leave the command's own quotes alone.Bash()
"with\"beforeCommand.Run, which escapes the argument again. Bash then saw\"(a literal quote) instead of quotes around an argument, so"a b"arrived as the two arguments"aandb".Tests
Test_Cmd_QuotedArguments, a quoted argument with spaces and a|.Test_Bash_QuotedArguments, where"a b"must arrive as one argument.Version
Bumped to 3.2.1, with a changelog entry in the README. The package is ready to publish from the portal.
🤖 Generated with Claude Code