Repository navigation
fix(core): quote child arguments so MSYS children receive them intact - #3728
Conversation
629f8be to
d176798
Compare
d176798 to
43baaa9
Compare
|
@KuSh rebased this onto current develop. The conflicts came from the recent runner.rs and utils.rs changes, and it is one clean commit again. On MSVC fmt and clippy are clean with -D warnings, and 3686 unit tests pass, with the same three failures that also fail on a clean develop on this machine. One scope call worth flagging up front. develop added new spawn sites in bun_cmd, deno_cmd, phpt_cmd, sqlfluff_cmd, ast_grep_cmd and ctest_cmd, and I left those alone deliberately. They launch native Win32 binaries, where UCRT parses a bare quote correctly, so the bug does not apply there and guarding them would put raw_arg on a path that is not broken. That is also why the guard here only kicks in when the argument actually contains a quote. If you would rather see them covered anyway for consistency, say so and I will add them. |
KuSh
left a comment
There was a problem hiding this comment.
Round 1 of 3 — CHANGES REQUESTED (one line)
Claim: On Windows, re-encode a child argument that contains a " using libuv's quote_cmd_arg form, so MSYS/Cygwin children resolved through PATH receive it intact (#3727).
Scope: accept (round 1, frozen). The diagnosis is right, the encoding is right, and the blast radius is exactly one branch (s.contains('"')) on Windows only. No other open PR touches these files.
Ran: verbatim ports of libuv's quote_cmd_arg, Rust std's make_command_line, the MSVCRT/CommandLineToArgvW parser and Cygwin's own build_argv/quoted/globify (the winshell=1 path, which is the one a native parent like rtk.exe triggers — confirmed at dcrt0.cc:909, NOTSTATE (myself, PID_CYGPARENT)), over 3915 inputs: exhaustive to length 5 across {a, space, ", \, *} plus real-world shapes.
| check | result |
|---|---|
| encoder vs libuv, on quote-bearing args | 0 mismatches / 2545 |
| MSVCRT round-trip after the change | 0 failures / 3915 |
| Cygwin round-trip, newly fixed | 958 |
| Cygwin round-trip, regressions | 0 |
args without a " whose bytes changed |
0 |
| Linux before/after, 10 command shapes | byte-identical, exit codes equal |
Savings are not in play — this is not a filter change, and the Linux output is byte-for-byte unchanged (floor is 20% per CONTRIBUTING.md; it does not apply here).
The end-to-end confirmation of your diagnosis, through the Cygwin parser:
arg cmdline before cmdline after MSYS receives before → after
a"b a\"b "a\"b" a\b → a"b ← #3727, fixed
say "hi" "say \"hi\"" "say \"hi\"" ok → ok ← space, so std already wrapped it
That second row is why this stayed hidden: std wraps on space or tab, so only a quote without a space was ever corrupted.
CI @43baaa90: 10/10 green (fmt, clippy, semgrep, Security Scan, benchmark, doc review, test presence, and test on ubuntu + macos + windows) — but against a stale base, so it does not gate this merge. See the one blocking item. The Windows job passing is real evidence that the #[cfg(windows)] code compiles and windows_child_quoting_test.rs runs there; it is just not evidence about current develop.
Blocks merge (1, frozen at round 1)
-
cargo fmt --all -- --checkfails once this is merged into currentdevelop— and CI did not catch it, because CI never tested that merge.The run on this head checked out:
HEAD is now at d9bdc8a Merge 43baaa9070b5e1a53822145483c9357b9139f7cf into d402152ffa050ca3753672e3d49c3f2ff498a07bd402152fis this branch's old merge-base, not currentdevelop(8495f63b). An approvedaction_requiredrun replays the merge ref frozen at run-creation time (2026-09-14), which predates #3782 — the Rust edition 2024 /style_edition = 2024migration. So this PR's green is green against a four-day-old develop.Merged into the real current
develop, rustfmt wants four spots changed (3 import orderings, 1 chained call). Nothing is wrong with your change; this is merge skew from #3782 landing after you branched. Verified on the actual merge:tree fmt clippy -D warningscargo test --alldevelop+ this PR4 diffs clean 3808 pass develop+ this PR + fixupclean clean 3808 pass What to do: rebase onto current
developand runcargo fmt --all. That produces exactly these four changes (3 import reorderings where style edition 2024 sortsChildArgExtbeforeresolved_command, and one line wrap infind_cmd.rs:268), and it is also what makes GitHub compute a fresh merge ref — so CI finally runs against the real current develop instead of the stale base above. That run is the one that should gate this merge.
Checked and correct — no need to re-verify
- The escaping state machine is libuv-exact. Byte-identical to
quote_cmd_argon all 2545 quote-bearing inputs, including every case in libuv's own doc comment. - Mixing
raw_argandargis sound. Both land in the sameVec<Arg>; order and space separation are preserved. - The
.bat/.cmdguard is load-bearing, not decoration.make_bat_command_linein std passesArg::Rawthrough as-is ("It's the user's responsibility…"), so without your guard a quote-bearing arg to a batch file would bypassappend_bat_arg— i.e. std's CVE-2024-24576 mitigation. Good catch, and the right call. - The guard cannot be fooled.
which::whichreturns the real resolved path with its extension, and std's ownresolve_exeonly ever appends.exe, never the fullPATHEXTlist — so a bare program name can't become a batch file behindis_batch_program's back. Case is handled byeq_ignore_ascii_case. - No call site changed its argument vector. Diffed each one: nothing added, dropped or reordered.
- Off Windows this is a true no-op —
push_child_argforwards tocmd.arg, and 10 real before/after command shapes are byte-identical.
Optional — will not hold merge
tests/windows_child_quoting_test.rsreturns silently on both skip paths, so it reports green whether or not it tested anything. Aneprintln!on skip would keep the signal if a runner image ever moves Git.push_child_argroutes a non-UTF-8OsStrback to std viato_str() == None. The one call site actually carryingOsStrings isrun_passthrough(runner.rs:284, from clap'sargs_os). Narrow, and it degrades to today's behaviour rather than something worse.
Filed as follow-ups
- #4101 —
treeis the one remaining sibling in this family.src/cmds/system/tree.rs:35still forwards rtk's own args with plaincmd.argwhilels/wc/findwere converted, and MSYS2 ships an MSYS-linkedtree. (-Ion line 32 is rtk-generated and safe.) I checked the rest ofsrc/cmds/system/— this is the only gap. - #4102 — the
"trigger covers one of several characters Cygwin reinterprets.build_argvtreats'as a quote too when the parent is not a Cygwin process, and every non-argv[0] word goes throughglobify. Verified against my Cygwin port:rtk grep "it's" freaches MSYS grep asits— the apostrophe is silently dropped, and it searches for the wrong string. Identical before and after your change, so this is pre-existing and not yours to fix here; #3727's repro is the double-quote case and you fixed that. Worth its own issue as the sequel, because widening the trigger also suppresses child-side globbing, which is right forsearch.rspatterns but a real behaviour change forls/findpath operands — a decision that deserves its own PR, not a late addition to this one.
Hypotheses built and dropped
is_batch_programbypassed via a trailing-dot program name — unreachable: such a filename cannot exist on Windows, andCreateProcesscannot launch a.batdirectly anyway.is_batch_programbypassed whenwhichfails andCommand::new(name)keeps a bare name — std's ownis_batch_filealso resolves to false there, so it takes the ordinary path; no raw arg reaches cmd.exe.GLOB_BRACEsplitsx{1,2}into two argv entries — plausible from reading Cygwin'sglobify, but my parser port does not modelGLOB_BRACE, so I did not confirm it and am not asserting it. It belongs in the follow-up issue as a suspected member of the same class, to be confirmed on a real MSYS box.- This should route through
arg_tokenizer— no. The PR adds zero classification logic; its only predicate iss.contains('"'), a property of the bytes rather than of the argument's role. See your questions below.
Your questions
- "develop added new spawn sites in bun_cmd, deno_cmd, phpt_cmd, sqlfluff_cmd, ast_grep_cmd and ctest_cmd, and I left those alone deliberately… If you would rather see them covered anyway for consistency, say so and I will add them."
→ Agreed, leave them. Your conclusion is right. One correction to the reasoning, in your favour: the worry that this would "putraw_argon a path that is not broken" doesn't hold empirically — the MSVCRT round-trip is lossless in all 3915 cases, so applying the encoding to a native child is a no-op, not a risk. So blanket coverage would be safe; it's just unnecessary for native-only binaries, and keeping the trigger narrow keeps the diff honest. One exception: please addtree.rs— same coreutils family, and MSYS2'streeis MSYS-linked. Filed as #4101; folding it into this PR is welcome if you'd rather not leave it open.
Next
Land the fmt fixup (mine, or your own rebase + cargo fmt --all) and let the fresh CI run go green against current develop — then this merges. Everything else above is a follow-up issue, not a change to this PR.
Rounds: 1/3. Threads: 0 open, 0 resolved this round.
43baaa9 to
078bde5
Compare
std::process::Command wraps an argument in quotes only when it contains a space or a tab, so an argument like a"b reaches the raw command line bare. MSVCRT and UCRT parse that back correctly, Cygwin and MSYS do not, which is why `rtk grep -c '"type"'` silently matched nothing (rtk-ai#3727). Re-encode with libuv's quote_cmd_arg rules, and only when the argument contains a quote, so every argument that works today keeps its exact bytes. Batch programs stay on the old path: raw_arg would bypass std's CVE-2024-24576 mitigation, and gradlew.bat and mvnw.cmd both reach run_passthrough. tree forwards the user's own arguments the same way (rtk-ai#4101). MSYS2 ships an MSYS-linked tree, so it belongs with ls, wc and find rather than with the native-only spawn sites, which are deliberately left alone.
078bde5 to
eb11789
Compare
KuSh
left a comment
There was a problem hiding this comment.
Round 2 of 3 — APPROVED, follow-up filed
Claim: On Windows, re-encode a child argument that contains a " using libuv's quote_cmd_arg form, so MSYS/Cygwin children resolved through PATH receive it intact (#3727).
Scope: accept (frozen at round 1).
Ran: the round-1 matrix re-run against the new head, plus the two things this push changed. quote_arg_for_child, the ChildArgExt impl and push_child_arg are byte-identical to the reviewed head (md5-matched), so round 1's differential evidence stands without re-deriving it: encoder vs libuv 0 mismatches / 2545 quote-bearing inputs, MSVCRT round-trip 0 failures / 3915, Cygwin round-trip 958 fixed / 0 regressions. Savings do not apply — not a filter change, and Linux output is byte-identical.
CI @eb11789d: 10/10 green, including test (windows-latest) — the only platform where this change has any runtime effect at all.
One caveat, the same one as round 1 and worth stating because it is systematic rather than a one-off: the run checks out Merge eb11789d into 6d104308, i.e. develop as of your push, not current develop (0022842e, #3008 landed about five hours later). An approved action_required run replays the merge ref frozen at run-creation time. Last round that gap hid a real fmt failure; this round it hides nothing, because I ran the gate against current develop myself — that is the table below, not CI's.
Blocks merge (0 — round 1's single item is cleared)
Round 1's blocker was that cargo fmt --all -- --check failed once the branch was merged into current develop, because #3782's edition-2024 migration landed after the branch was cut. The rebase fixes it. Verified on the merge with current develop (0022842e, which is newer than the base CI used):
| gate on develop + this PR | result |
|---|---|
cargo fmt --all -- --check |
0 diffs |
cargo clippy --all-targets -- -D warnings |
clean |
cargo test --all |
3844 pass, 0 fail |
Rebase integrity — nothing was dropped in the rebase. child_arg/child_args call counts per file, reviewed head → this head:
find_cmd 6→6 ls 4→4 search 9→9 wc 1→1 runner 1→1 main 4→4 utils 12→12
tree 0→1 ← the only change, and the one I asked for
Fixed since round 1
tree.rsconverted (cmd.child_args(args)). This is #4101, and it is now fixed inside this PR rather than left as a follow-up. The rtk-generated-I <NOISE_DIRS>flag above it stays on plainarg, which is correct — it is rtk's own string and holds no quote.- The Windows regression test no longer skips silently. Both paths now print why, so a runner image that moves Git cannot quietly turn the one test guarding this PR into a no-op.
Optional — will not hold merge
- The PR body's "Converted call sites" list does not mention
rtk tree, but still says "That is every place where an argument from rtk's own command line reaches a child resolved through PATH". Worth addingtreeto that sentence, andFixes #4101alongsideFixes #3727so the issue closes on merge. - My round-1 ask about the skipping test was only half right, and that is on me.
cargo testcaptures stdout/stderr for a passing test, so the neweprintln!lines are invisible in a normal CI run and only show under--nocaptureor when the test fails. They are still an improvement over a barereturnand I am not asking for more — noting it so nobody later reads the skip lines as a guarantee that CI would tell you. The form that would actually guarantee it is a hard failure gated on an env var set in CI, which is a bigger change than this PR should carry.
Filed as follow-ups
- #4116 —
push_child_argroutes a non-UTF-8OsStrback to std's encoding viato_str() == None, so an argument holding both an unpaired surrogate and a"is still passed mangled, with no diagnostic. Narrow, degrades to today's behaviour rather than to something worse, and not introduced by this PR — but the one call site actually carryingOsStrings isrun_passthrough, whose args come from clap'sargs_os, so it is reachable. Searched open and closed issues under three wordings first; nothing existed. - #4102 stays open and is explicitly not this PR's job: Cygwin also reinterprets
'and theglobifymetacharacters, sortk grep "it's"reaches MSYS grep asits. Verified identical before and after this change, i.e. pre-existing. #3727's repro is the double-quote case and this PR fixes that.
Checked and correct — no need to re-verify
Carried from round 1, all probed by execution: the escaping state machine is libuv-exact; mixing raw_arg and arg is sound; the .bat/.cmd guard is load-bearing (std's make_bat_command_line passes raw args through unescaped) and cannot be fooled, because which returns the resolved path with its extension and std's resolve_exe only ever appends .exe; no call-site conversion changed its argument vector; off Windows the whole change is a no-op.
New this round: the rebase preserved every conversion (table above), and tree.rs's argument vector is unchanged in count and order.
Hypotheses built and dropped
- The rebase onto a newer develop silently dropped a conversion — checked by counting
child_argoccurrences per file across both heads; every file matches except the intendedtree.rs.
Your questions
None since round 1 — this push came without a comment. Round 1's question about bun_cmd/deno_cmd/phpt_cmd/sqlfluff_cmd/ast_grep_cmd/ctest_cmd was answered there (leave them; they are native binaries) with the one exception of tree, which this push has now covered.
Next
Nothing — approving. The two Optional items are yours to take or leave and I will not hold the merge on either. If you want #4101 to close automatically, add Fixes #4101 and mention tree in the converted-call-sites sentence before you merge.
Rounds: 2/3. Threads: 0 open, 0 resolved this round.
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing for the path operands of ls, wc, tree, find and the search engines. clippy.toml bans `std::process::Command::new` so a future call site cannot reintroduce the bug by constructing a raw Command. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing for the path operands of ls, wc, tree, find and the search engines. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing for the path operands the user typed, including the verbatim vectors that passthrough and `rtk proxy` forward. A shell string is not an argument vector, so the `sh -c` and `cmd /C` sites stay on `std::process::Command`. `needs_quoting` decides the whole encoding but only runs on Windows, so it is asserted directly, on every platform, rather than through the one `#[cfg(windows)]` test that used to cover it. `.semgrep.yml` matched `Command::new` by name, so renaming the constructor would have retired `dynamic-command-execution` and `interpreter-execution` across the tree. Both rules now match `ChildCommand::new` as well. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing for the operands rtk has itself parsed as paths, in ls, wc, find and the search engines. A vector rtk has not split — every passthrough, and `rtk proxy` — stays on the literal default, because a glob that does not expand is visible while a pattern the child reinterprets is not. A shell string is not an argument vector at all, so the `sh -c` and `cmd /C` sites stay on `std::process::Command`. `needs_quoting` decides the whole encoding but only runs on Windows, so it is asserted directly, on every platform, rather than through the one `#[cfg(windows)]` test that used to cover it. `.semgrep.yml` matched `Command::new` by name, so renaming the constructor would have retired `dynamic-command-execution` and `interpreter-execution` across the tree. Both rules now match `ChildCommand::new` as well. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing for the operands rtk has itself parsed as paths, in ls, wc, find and the search engines. A vector rtk has not split — every passthrough, and `rtk proxy` — stays on the literal default, because a glob that does not expand is visible while a pattern the child reinterprets is not. A shell string is not an argument vector at all, so the `sh -c` and `cmd /C` sites stay on `std::process::Command`. Only `raw_arg` stays Windows-only. The encoding decision itself is made on every platform, so the batch-shim guard, both operand kinds and the exact bytes a child receives are asserted everywhere, instead of through the one `#[cfg(windows)]` test that used to cover them: code that no target compiles is code that no test can reach. A further test pins the `glob_arg` call sites, since on Unix `push` cannot tell the two spellings apart and so neither can any behavioural test. `.semgrep.yml` matched `Command::new` by name, so renaming the constructor would have retired `dynamic-command-execution` and `interpreter-execution` across the tree. Both rules now match `ChildCommand::new` as well. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing, and it is used only where rtk has itself split the vector and knows the slice is path operands: ls, find and the search engines. A vector rtk has not split still holds flag values — `wc --files0-from F` names a file, `tree -P` a pattern — so passthrough, `rtk proxy`, `tree` and `wc` keep the literal default, a glob that does not expand being visible where a reinterpreted operand is not. A shell string is not an argument vector at all, so the `sh -c` and `cmd /C` sites stay on `std::process::Command`. Only `raw_arg` stays Windows-only. The encoding decision itself is made on every platform, so the batch-shim guard, both operand kinds and the exact bytes a child receives are asserted everywhere, instead of through the one `#[cfg(windows)]` test that used to cover them: code that no target compiles is code that no test can reach. A further test pins the `glob_arg` call sites, since on Unix `push` cannot tell the two spellings apart and so neither can any behavioural test. `.semgrep.yml` matched `Command::new` by name, so renaming the constructor would have retired `dynamic-command-execution` and `interpreter-execution` across the tree. Both rules now match `ChildCommand::new` as well. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing, and it is used only where a slice is bounded by the tool's own grammar: find's operands, which end at its first expression token, and the search engines', which the arg_tokenizer separates from the patterns. Splitting on a leading dash is not that — `ls -I <pattern>`, `wc --files0-from <file>` and `tree -P <pattern>` all leave a value among the positionals — so ls, wc, tree, every passthrough and `rtk proxy` keep the literal default, a glob that does not expand being visible where a reinterpreted operand is not. A shell string is not an argument vector at all, so the `sh -c` and `cmd /C` sites stay on `std::process::Command`. Only `raw_arg` stays Windows-only. The encoding decision itself is made on every platform, so the batch-shim guard, both operand kinds and the exact bytes a child receives are asserted everywhere, instead of through the one `#[cfg(windows)]` test that used to cover them: code that no target compiles is code that no test can reach. A further test pins the `glob_arg` call sites, since on Unix `push` cannot tell the two spellings apart and so neither can any behavioural test. `.semgrep.yml` matched `Command::new` by name, so renaming the constructor would have retired `dynamic-command-execution` and `interpreter-execution` across the tree. Both rules now match `ChildCommand::new` as well. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing, and it is used only where a slice is bounded by the tool's own grammar: find's operands, which end at its first expression token, and the search engines', which the arg_tokenizer separates from the patterns. Splitting on a leading dash is not that — `ls -I <pattern>`, `wc --files0-from <file>` and `tree -P <pattern>` all leave a value among the positionals — so ls, wc, tree, every passthrough and `rtk proxy` keep the literal default, a glob that does not expand being visible where a reinterpreted operand is not. A shell string is not an argument vector at all, so the `sh -c` and `cmd /C` sites stay on `std::process::Command`. Only `raw_arg` stays Windows-only. The encoding decision itself is made on every platform, so the batch-shim guard, both operand kinds and the exact bytes a child receives are asserted everywhere, instead of through the one `#[cfg(windows)]` test that used to cover them: code that no target compiles is code that no test can reach. A further test pins the `glob_arg` call sites, since on Unix `push` cannot tell the two spellings apart and so neither can any behavioural test. `.semgrep.yml` matched `Command::new` by name, so renaming the constructor would have retired `dynamic-command-execution` and `interpreter-execution` across the tree. Both rules now match `ChildCommand::new` as well. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing, and it is used only where a slice is bounded by the tool's own grammar: find's operands, which end at its first expression token, and the search engines', which the arg_tokenizer separates from the patterns. Splitting on a leading dash is not that — `ls -I <pattern>`, `wc --files0-from <file>` and `tree -P <pattern>` all leave a value among the positionals — so ls, wc, tree, every passthrough and `rtk proxy` keep the literal default, a glob that does not expand being visible where a reinterpreted operand is not. A shell string is not an argument vector at all, so the `sh -c` and `cmd /C` sites stay on `std::process::Command`. Only `raw_arg` stays Windows-only. The encoding decision itself is made on every platform, so the batch-shim guard, both operand kinds and the exact bytes a child receives are asserted everywhere, instead of through the one `#[cfg(windows)]` test that used to cover them: code that no target compiles is code that no test can reach. A further test pins the `glob_arg` call sites, since on Unix `push` cannot tell the two spellings apart and so neither can any behavioural test. `.semgrep.yml` matched `Command::new` by name, so renaming the constructor would have retired `dynamic-command-execution` and `interpreter-execution` across the tree. Both rules now match `ChildCommand::new` as well. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing, and it is used only where a slice is bounded by the tool's own grammar: find's operands, which end at its first expression token, and the search engines', which the arg_tokenizer separates from the patterns. Splitting on a leading dash is not that — `ls -I <pattern>`, `wc --files0-from <file>` and `tree -P <pattern>` all leave a value among the positionals — so ls, wc, tree, every passthrough and `rtk proxy` keep the literal default, a glob that does not expand being visible where a reinterpreted operand is not. A shell string is not an argument vector at all, so the `sh -c` and `cmd /C` sites stay on `std::process::Command`. Only `raw_arg` stays Windows-only. The encoding decision itself is made on every platform, so the batch-shim guard, both operand kinds and the exact bytes a child receives are asserted everywhere, instead of through the one `#[cfg(windows)]` test that used to cover them: code that no target compiles is code that no test can reach. A further test pins the `glob_arg` call sites, since on Unix `push` cannot tell the two spellings apart and so neither can any behavioural test. `.semgrep.yml` matched `Command::new` by name, so renaming the constructor would have retired `dynamic-command-execution` and `interpreter-execution` across the tree. Both rules now match `ChildCommand::new` as well. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ble name Round-1 review of rtk-ai#4125. Resolving the program fixed the resolution-side instance and left the class: once a command is built, every `execve` failure was a Rust error again, and `which` cannot tell "nothing by that name" from "there, but you cannot run it". - `Launch::Unrunnable` carries the message *and* the code, so 126 — a directory, a file without `+x` — is reported where `sh`, `dash` and `bash` report it, and 127 stays for a genuinely missing program. Only a spelling that addresses the filesystem is stat'd: a bare `PATH` name without `+x` answers 127, which is what those shells do. - `spawn_failure` maps the post-spawn errors the same way, so a CRLF shebang (`#!/bin/sh\r`), a missing interpreter and a bad executable format render through the runners' own failure path instead of an anyhow chain on stderr. - A `--shell` name that cannot be resolved is the third arm, and now answers like an unrunnable program rather than with an RTK error. `err`/`test`/`summary` also report `--shell` misuse themselves. They are `PASSTHROUGH`, so a clap error under them used to fall through to `run_fallback` and exec a binary named after the subcommand: `rtk err --shell` exited 127 with "No such file or directory", and `rtk test --shell` exited 0 in silence. `err` and `summary` join `RTK_META_COMMANDS`; `test` cannot — it deliberately shadows the POSIX `test` binary — so an argv carrying RTK's own `--shell` reports the flag error before the fallback runs. The arity error is raised by the subcommand that was asked, so its usage line names it, and both it and `command_from_args` now quote one shared message. Two more from the review's optional list: `direct_command` passes caller argv through `child_args`, the encoding MSYS/Cygwin children need on Windows (rtk-ai#3728), and `display_args` quotes every shell metacharacter, so a tracking label reads back as the command that ran rather than as something a shell would expand. `rtk test '(' cmd ')'` keeps its grouping, which `is_native_test_expression` already recognised but the negation split did not.
…ble name Round-1 review of rtk-ai#4125. Resolving the program fixed the resolution-side instance and left the class: once a command is built, every `execve` failure was a Rust error again, and `which` cannot tell "nothing by that name" from "there, but you cannot run it". - `Launch::Unrunnable` carries the message *and* the code, so 126 — a directory, a file without `+x` — is reported where `sh`, `dash` and `bash` report it, and 127 stays for a genuinely missing program. Only a spelling that addresses the filesystem is stat'd: a bare `PATH` name without `+x` answers 127, which is what those shells do. - `spawn_failure` maps the post-spawn errors the same way, so a CRLF shebang (`#!/bin/sh\r`), a missing interpreter and a bad executable format render through the runners' own failure path instead of an anyhow chain on stderr. - A `--shell` name that cannot be resolved is the third arm, and now answers like an unrunnable program rather than with an RTK error. `err`/`test`/`summary` also report `--shell` misuse themselves. They are `PASSTHROUGH`, so a clap error under them used to fall through to `run_fallback` and exec a binary named after the subcommand: `rtk err --shell` exited 127 with "No such file or directory", and `rtk test --shell` exited 0 in silence. `err` and `summary` join `RTK_META_COMMANDS`; `test` cannot — it deliberately shadows the POSIX `test` binary — so an argv carrying RTK's own `--shell` reports the flag error before the fallback runs. The arity error is raised by the subcommand that was asked, so its usage line names it, and both it and `command_from_args` now quote one shared message. Two more from the review's optional list: `direct_command` passes caller argv through `child_args`, the encoding MSYS/Cygwin children need on Windows (rtk-ai#3728), and `display_args` quotes every shell metacharacter, so a tracking label reads back as the command that ran rather than as something a shell would expand. `rtk test '(' cmd ')'` keeps its grouping, which `is_native_test_expression` already recognised but the negation split did not.
user_command spawned the multi-part route with plain Command::args, which predates rtk-ai#3728. An argument holding a `"` therefore reached an MSYS/Cygwin child re-encoded by std's rules instead of libuv's, e.g. `rtk err grep -c '"type"' f` under Git Bash. Route it through child_args like every other caller-supplied argument.
The new `#[cfg(windows)]` test asserted that `c"d` survives through `cmd /C echo`, and the Windows runner reported `"a b" "c\"d"`: `cmd.exe` does not parse backslash escapes, so it echoed the MSVC/libuv encoding `child_args` applies verbatim. The encoding was right; the witness was wrong. Use `rtk` itself as the child. `rtk rewrite` prints the command string it was given, so the argument only comes back unchanged if the quote survived encoding on the way out and parsing on the way in — which is exactly what `child_args` is for (rtk-ai#3728). Isolated `HOME`/`USERPROFILE` so the verdict does not depend on the runner's settings files.
The new `#[cfg(windows)]` test asserted that `c"d` survives through `cmd /C echo`, and the Windows runner reported `"a b" "c\"d"`: `cmd.exe` does not parse backslash escapes, so it echoed the MSVC/libuv encoding `child_args` applies verbatim. The encoding was right; the witness was wrong. Use `rtk` itself as the child. `rtk rewrite` prints the command string it was given, so the argument only comes back unchanged if the quote survived encoding on the way out and parsing on the way in — which is exactly what `child_args` is for (rtk-ai#3728). Isolated `HOME`/`USERPROFILE` so the verdict does not depend on the runner's settings files.
…ble name Round-1 review of rtk-ai#4125. Resolving the program fixed the resolution-side instance and left the class: once a command is built, every `execve` failure was a Rust error again, and `which` cannot tell "nothing by that name" from "there, but you cannot run it". - `Launch::Unrunnable` carries the message *and* the code, so 126 — a directory, a file without `+x` — is reported where `sh`, `dash` and `bash` report it, and 127 stays for a genuinely missing program. Only a spelling that addresses the filesystem is stat'd: a bare `PATH` name without `+x` answers 127, which is what those shells do. - `spawn_failure` maps the post-spawn errors the same way, so a CRLF shebang (`#!/bin/sh\r`), a missing interpreter and a bad executable format render through the runners' own failure path instead of an anyhow chain on stderr. - A `--shell` name that cannot be resolved is the third arm, and now answers like an unrunnable program rather than with an RTK error. `err`/`test`/`summary` also report `--shell` misuse themselves. They are `PASSTHROUGH`, so a clap error under them used to fall through to `run_fallback` and exec a binary named after the subcommand: `rtk err --shell` exited 127 with "No such file or directory", and `rtk test --shell` exited 0 in silence. `err` and `summary` join `RTK_META_COMMANDS`; `test` cannot — it deliberately shadows the POSIX `test` binary — so an argv carrying RTK's own `--shell` reports the flag error before the fallback runs. The arity error is raised by the subcommand that was asked, so its usage line names it, and both it and `command_from_args` now quote one shared message. Two more from the review's optional list: `direct_command` passes caller argv through `child_args`, the encoding MSYS/Cygwin children need on Windows (rtk-ai#3728), and `display_args` quotes every shell metacharacter, so a tracking label reads back as the command that ran rather than as something a shell would expand. `rtk test '(' cmd ')'` keeps its grouping, which `is_native_test_expression` already recognised but the negation split did not.
The new `#[cfg(windows)]` test asserted that `c"d` survives through `cmd /C echo`, and the Windows runner reported `"a b" "c\"d"`: `cmd.exe` does not parse backslash escapes, so it echoed the MSVC/libuv encoding `child_args` applies verbatim. The encoding was right; the witness was wrong. Use `rtk` itself as the child. `rtk rewrite` prints the command string it was given, so the argument only comes back unchanged if the quote survived encoding on the way out and parsing on the way in — which is exactly what `child_args` is for (rtk-ai#3728). Isolated `HOME`/`USERPROFILE` so the verdict does not depend on the runner's settings files.
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing, and it is used only where a slice is bounded by the tool's own grammar: find's operands, which end at its first expression token, and the search engines', which the arg_tokenizer separates from the patterns. Splitting on a leading dash is not that — `ls -I <pattern>`, `wc --files0-from <file>` and `tree -P <pattern>` all leave a value among the positionals — so ls, wc, tree, every passthrough and `rtk proxy` keep the literal default, a glob that does not expand being visible where a reinterpreted operand is not. A shell string is not an argument vector at all, so the `sh -c` and `cmd /C` sites stay on `std::process::Command`. Only `raw_arg` stays Windows-only. The encoding decision itself is made on every platform, so the batch-shim guard, both operand kinds and the exact bytes a child receives are asserted everywhere, instead of through the one `#[cfg(windows)]` test that used to cover them: code that no target compiles is code that no test can reach. A further test pins the `glob_arg` call sites, since on Unix `push` cannot tell the two spellings apart and so neither can any behavioural test. `.semgrep.yml` matched `Command::new` by name, so renaming the constructor would have retired `dynamic-command-execution` and `interpreter-execution` across the tree. Both rules now match `ChildCommand::new` as well. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ble name Round-1 review of rtk-ai#4125. Resolving the program fixed the resolution-side instance and left the class: once a command is built, every `execve` failure was a Rust error again, and `which` cannot tell "nothing by that name" from "there, but you cannot run it". - `Launch::Unrunnable` carries the message *and* the code, so 126 — a directory, a file without `+x` — is reported where `sh`, `dash` and `bash` report it, and 127 stays for a genuinely missing program. Only a spelling that addresses the filesystem is stat'd: a bare `PATH` name without `+x` answers 127, which is what those shells do. - `spawn_failure` maps the post-spawn errors the same way, so a CRLF shebang (`#!/bin/sh\r`), a missing interpreter and a bad executable format render through the runners' own failure path instead of an anyhow chain on stderr. - A `--shell` name that cannot be resolved is the third arm, and now answers like an unrunnable program rather than with an RTK error. `err`/`test`/`summary` also report `--shell` misuse themselves. They are `PASSTHROUGH`, so a clap error under them used to fall through to `run_fallback` and exec a binary named after the subcommand: `rtk err --shell` exited 127 with "No such file or directory", and `rtk test --shell` exited 0 in silence. `err` and `summary` join `RTK_META_COMMANDS`; `test` cannot — it deliberately shadows the POSIX `test` binary — so an argv carrying RTK's own `--shell` reports the flag error before the fallback runs. The arity error is raised by the subcommand that was asked, so its usage line names it, and both it and `command_from_args` now quote one shared message. Two more from the review's optional list: `direct_command` passes caller argv through `child_args`, the encoding MSYS/Cygwin children need on Windows (rtk-ai#3728), and `display_args` quotes every shell metacharacter, so a tracking label reads back as the command that ran rather than as something a shell would expand. `rtk test '(' cmd ')'` keeps its grouping, which `is_native_test_expression` already recognised but the negation split did not.
The new `#[cfg(windows)]` test asserted that `c"d` survives through `cmd /C echo`, and the Windows runner reported `"a b" "c\"d"`: `cmd.exe` does not parse backslash escapes, so it echoed the MSVC/libuv encoding `child_args` applies verbatim. The encoding was right; the witness was wrong. Use `rtk` itself as the child. `rtk rewrite` prints the command string it was given, so the argument only comes back unchanged if the quote survived encoding on the way out and parsing on the way in — which is exactly what `child_args` is for (rtk-ai#3728). Isolated `HOME`/`USERPROFILE` so the verdict does not depend on the runner's settings files.
…ble name Round-1 review of rtk-ai#4125. Resolving the program fixed the resolution-side instance and left the class: once a command is built, every `execve` failure was a Rust error again, and `which` cannot tell "nothing by that name" from "there, but you cannot run it". - `Launch::Unrunnable` carries the message *and* the code, so 126 — a directory, a file without `+x` — is reported where `sh`, `dash` and `bash` report it, and 127 stays for a genuinely missing program. Only a spelling that addresses the filesystem is stat'd: a bare `PATH` name without `+x` answers 127, which is what those shells do. - `spawn_failure` maps the post-spawn errors the same way, so a CRLF shebang (`#!/bin/sh\r`), a missing interpreter and a bad executable format render through the runners' own failure path instead of an anyhow chain on stderr. - A `--shell` name that cannot be resolved is the third arm, and now answers like an unrunnable program rather than with an RTK error. `err`/`test`/`summary` also report `--shell` misuse themselves. They are `PASSTHROUGH`, so a clap error under them used to fall through to `run_fallback` and exec a binary named after the subcommand: `rtk err --shell` exited 127 with "No such file or directory", and `rtk test --shell` exited 0 in silence. `err` and `summary` join `RTK_META_COMMANDS`; `test` cannot — it deliberately shadows the POSIX `test` binary — so an argv carrying RTK's own `--shell` reports the flag error before the fallback runs. The arity error is raised by the subcommand that was asked, so its usage line names it, and both it and `command_from_args` now quote one shared message. Two more from the review's optional list: `direct_command` passes caller argv through `child_args`, the encoding MSYS/Cygwin children need on Windows (rtk-ai#3728), and `display_args` quotes every shell metacharacter, so a tracking label reads back as the command that ran rather than as something a shell would expand. `rtk test '(' cmd ')'` keeps its grouping, which `is_native_test_expression` already recognised but the negation split did not.
The new `#[cfg(windows)]` test asserted that `c"d` survives through `cmd /C echo`, and the Windows runner reported `"a b" "c\"d"`: `cmd.exe` does not parse backslash escapes, so it echoed the MSVC/libuv encoding `child_args` applies verbatim. The encoding was right; the witness was wrong. Use `rtk` itself as the child. `rtk rewrite` prints the command string it was given, so the argument only comes back unchanged if the quote survived encoding on the way out and parsing on the way in — which is exactly what `child_args` is for (rtk-ai#3728). Isolated `HOME`/`USERPROFILE` so the verdict does not depend on the runner's settings files.
`ChildArgExt::child_arg` requires every call site to remember a second name for `arg`. `tree.rs` did not, and the omission survived a full review round on rtk-ai#3728 before it was caught and patched by hand (rtk-ai#4101). That is the failure mode this removes: the encoding becomes a property of the type rather than a convention a call site can forget. An extension trait cannot do it. Inherent methods win over trait methods, so a trait declaring `fn arg` for `Command` compiles and is then never called. The encoding has to live on a type that does not have std's `arg` at all, so `resolved_command` returns `ChildCommand`, whose `arg`/`args` encode. There is deliberately no `Deref`, which would put std's inherent `arg` back within reach via `(&mut *cmd).arg(..)`. `arg` is the literal default and quotes on anything Cygwin's `build_argv` and `globify` reinterpret, which closes rtk-ai#4102: `rtk grep "it's"` reached MSYS grep as `its`. `glob_arg` keeps child-side globbing, and it is used only where a slice is bounded by the tool's own grammar: find's operands, which end at its first expression token, and the search engines', which the arg_tokenizer separates from the patterns. Splitting on a leading dash is not that — `ls -I <pattern>`, `wc --files0-from <file>` and `tree -P <pattern>` all leave a value among the positionals — so ls, wc, tree, every passthrough, `rtk proxy` and the argv form of `rtk run`/`err`/`test`/`summary` keep the literal default, a glob that does not expand being visible where a reinterpreted operand is not. A shell script is one argument to its shell, and an MSYS `sh` or `bash` re-parses it like any other child, so shells get the literal encoding too, except `cmd`, which parses its command line by its own rules and keeps std's encoding. Only `raw_arg` stays Windows-only. The encoding decision itself is made on every platform, so the batch-shim guard, both operand kinds and the exact bytes a child receives are asserted everywhere, instead of through the one `#[cfg(windows)]` test that used to cover them: code that no target compiles is code that no test can reach. A further test pins the `glob_arg` call sites, since on Unix `push` cannot tell the two spellings apart and so neither can any behavioural test. `.semgrep.yml` matched `Command::new` by name, so renaming the constructor would have retired `dynamic-command-execution` and `interpreter-execution` across the tree. Both rules now match `ChildCommand::new` as well. Fixes rtk-ai#4102 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
On Windows
std::process::Commandwraps an argument in quotes only when it holds a space or a tab, soa"breaches the raw command line bare, asa\"b. MSVCRT/UCRT children parse that back correctly; Cygwin/MSYS children read the\"as a backslash and glue the surrounding arguments together. Sincewhichresolvesgrep,find,ls,wcand the rest ofusr/binto the MSYS binaries Git for Windows ships,rtk grep -c '"type"' filereported 0 matches and exit 1 while the nativertk rgwas unaffected (#3727).quote_arg_for_childinsrc/core/utils.rsemits the encoding libuv'squote_cmd_arguses — the form both parsers agree on — and aChildArgExttrait (child_arg/child_args) puts it in front of the child's command line. std already produces those same bytes for every other argument, so only an argument that actually contains a"leaves theCommand::argpath; everything else is encoded exactly as before..bat/.cmdprograms stay on std's path unconditionally, since cmd.exe parses by its own rules andraw_argwould bypass the escaping std applies for them.Converted call sites:
rtk grep/rtk rg(structural, passthrough and--version/--help),rtk find,rtk ls,rtk wc,rtk proxy,runner::run_passthroughand the unknown-command fallback inmain.rs. That is every place where an argument from rtk's own command line reaches a child resolved through PATH, sosed,awk,sort,trand friends are covered too when they arrive through the fallback.Out of scope
rtk err,rtk runandrtk summaryhand a whole string tocmd /Cinstead of an argument vector, which is a separate problem (#2985, #2389, #3704). MSYS2's own POSIX-path conversion of arguments (MSYS2_ARG_CONV_EXCL) sits above the command line and is left alone.Test plan
cargo fmt --all -- --check(0),cargo clippy --all-targets -- -D warnings(0),cargo test— 2647 unit tests and every integration binary pass.src/core/utils.rsfor the libuv rules and the.batguard; the encoder itself compiles and is tested on every platform.tests/windows_child_quoting_test.rs(#![cfg(windows)], silently skipped when no MSYSgrep.exeis around) drivesrtk grep -c '"type"' q.jsonlat the Git-for-Windows grep. With the fix disabled it fails withrtk grep exited Some(1), expected 0; with it, green.rtk grep -c '"type"' q.jsonl→1(was0, exit 1), andrtk printf '<%s> ' 'a"b' 'c d' '"type"'→<a"b> <c d> <"type">.rtk find,rtk lsandrtk wcunchanged on ordinary arguments.Built and tested on both
stable-x86_64-pc-windows-gnuandstable-x86_64-pc-windows-msvc. On both,core::stream::tests::test_read_lines_lossy_preserves_lines_after_invalid_utf8andhooks::hook_cmd::tests::test_claude_pipeline_rewrites_only_safe_final_stagefail on unmodifieddevelop(322db4d) here as well, so those two are pre-existing.Fixes #3727