Repository navigation
Conversation
`rtk run -c` and `err`/`test`/`summary --shell cmd` passed the script to cmd.exe through `child_arg`, whose escaping follows the C runtime's rules. cmd parses its command string its own way: it strips the first and last quote and does no backslash processing. A script's own quotes therefore arrived as `\"`, which split quoted arguments, exposed a quoted `&` as a command separator, and kept a script that starts with a quoted program path from ever starting. On Windows, pass `/S /C` and the script inside one extra pair of outer quotes through `CommandExt::raw_arg`, so cmd strips exactly that pair. Direct argv and every other shell keep their existing encoding. The fix and the two integration tests are ryanduguid's, from rtk-ai#4125's review. The unit test whose expectation assumed `[flag, script]` for the platform shell now accounts for cmd, and a Windows unit test pins the argument shape for `cmd` and `CMD.EXE`. Fixes rtk-ai#4288 Co-authored-by: Ryan Duguid <[email protected]>
📊 Automated PR Analysis
SummaryFixes cmd.exe script quoting on Windows: scripts run via Review Checklist
Linked issues: #4288 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Author
|
Closing in favour of #4103, which already carries this fix (see #4288 (comment)). |
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.
Fixes #4288.
rtk run -canderr/test/summary --shell cmdhanded the script to cmd.exe throughchild_arg, which escapes by C-runtime rules. cmd parses its command string differently: it strips the first and last quote and does no backslash processing. So a script's own quotes reached cmd as\".On Windows, this passes
/S /Cand the script inside one extra pair of outer quotes throughCommandExt::raw_arg, so cmd strips exactly that pair. This follows Rust's documented cmd example. Direct argv and every other shell keep their current encoding, and Linux and macOS are untouched (the branch is#[cfg(windows)]).The fix and the two integration tests are @ryanduguid's, from their review of #4125, and they are credited as co-author. On top of that:
common::rtk_command()and live inrun_shell_test.rs'swindowsmodule, because the fix(tests): keep the test suite and the developer's environment apart #3758 isolation scan rejectsCARGO_BIN_EXE_rtkoutsidetests/common.a_single_shell_phrase_falls_back_to_the_platform_shellassumed[flag, script]for the platform shell, so it failed on Windows with the fix. It now accounts for cmd.cmdandCMD.EXE.Verified on Windows 11, Git Bash,
x86_64-pc-windows-gnu, base develop e4f0509cargo fmt --all --checkpasses, andcargo clippy --all-targetsreports no warnings.cargo test --allgives 4075 passed / 2 failed. Both failures also fail on pristine develop on this machine (find_cmd::run_from_args_propagates_find_exit_status,stream::test_read_lines_lossy_preserves_lines_after_invalid_utf8).shell.rschange, both new integration tests and both affected unit tests fail. With it, they pass.I also ran an argv probe: a node child that prints the argv it receives, run under official v0.51.0 and under this branch. Each script went through all five forms:
run -c,run --shell CMD.EXE -c, anderr/test/summary --shell cmd.node argv.js "a b" c["\"a","b\"","c"]["a b","c"]"…\node dir\node.exe" argv.js "a b" cis not recognized["a b","c"]node argv.js "x & y" "(p)"["\"x","&","y\"","\"(p)\""]: the quoted&acted as a command separator["x & y","(p)"]node -e "process.exit(7)"run node argv.js "a b" '"q"' c["a b","\"q\"","c"]The last two rows go beyond what the issue reported. On v0.51.0, a quoted
&in a cmd script splits it into a second command, and a quoted argument can silently turn the script into something else that exits 0.Not verified: MSVC toolchain (ryanduguid validated the same
shell.rschange on Rust 1.91.0 MSVC), Linux and macOS (no code change there), and upstream CI. I have no merged PR here yet, so the workflow needs a maintainer to approve it before it runs.