Repository navigation
Quote arguments holding cmd.exe special characters - #36
Merged
Merged
Conversation
A .bat or .cmd program runs through cmd.exe, which acts on & | < > ^ outside quotes and splits batch arguments at , ; so an Arguments list element like 'a&ver', with no space to trigger quoting, ran ver instead of reaching the program. ConvertTo-PkArgumentString, and with it list Arguments, now quotes any element holding one of & | < > ^ ( ) , ; - harmless to programs that use the C runtime's rules, which drop the quotes. The README notes that cmd.exe still expands %NAME% inside quotes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cmd.exe also splits batch arguments at =, which stays unquoted because some programs read NAME=value from the command line themselves, and it counts an escaped \" as a quote, so an argument containing a quote can end up partly unquoted. The help and README now say so, next to %NAME% expansion. 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.
What was wrong
A
.bator.cmdprogram runs throughcmd.exe, which acts on&,|,<,>and^outside quotes and splits batch arguments at,and;. A list element only got quoted when it held a space, tab or quote, so a list inArgumentspassed elements like these to cmd as they were:a&vera, andverrana|bba^baba,b/a;bFile names can contain
&,^,,and;, so a batch over real files could run commands built from their names.What changed
ConvertTo-PkArgumentString, which listArgumentsgo through, also quotes an element holding& | < > ^ ( ) , ;. Programs that use the C runtime's rules drop the quotes, so they get the same arguments as before.%NAME%is expanded even inside quotes.=still splits batch arguments. It's left unquoted because some programs, such asmsiexec, readNAME=valuefrom the command line themselves."can end up partly unquoted, because cmd counts an escaped\"as a quote.Things that change for users:
cmd.exe /cnow has these arguments quoted.\\.Testing
New harness checks:
.cmdfile gets each ofa&ver,a|b,a^b,a,b,a;band(x)as one argument, with nothing else runFive of the
.cmdchecks and the quoting check fail onmain.Full harness:
ALL PASSED (387 assertions)on Windows PowerShell 5.1 and PowerShell 7, none skipped.🤖 Generated with Claude Code