Repository navigation
fix(windows): quote glob patterns passed to MSYS children - #4260
mrhard9090 wants to merge 1 commit into
Conversation
An MSYS/Cygwin child such as Git Bash's grep expands *, ?, [ and { in every argument it receives unquoted. std only quotes arguments with spaces or tabs, so a pattern like .{0,20}foo reached grep as .0foo and .20foo. Re-encode those arguments with quote_arg_for_child too, as is already done for arguments holding a quote.
Refs rtk-ai#4256
📊 Automated PR Analysis
SummaryFixes a Windows bug where MSYS/Cygwin child processes (like Git Bash's grep) would glob-expand unquoted Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
|
The find case you flagged as unconfirmed: I have a repro that was broken before this PR and is fixed by it. Provenance: AI-assisted, human-directed. Built both
The same shape this issue's own original report used, at three match counts:
The 1-match row is the one worth naming: it isn't an error, it's a successful-looking run that quietly loses the recursive part of the pattern, because the MSYS child glob-expands Checked against a real, non-corrupted Byte-identical. No regression found. A plain Suite at Not checked: rtk started from PowerShell or cmd (no |
|
Thanks for this one, and for the clear write-up. I tested it natively on Windows (MSVC build, real Git Bash, throwaway dirs) and the bug is real: on develop The catch is callers that don't expand globs. From PowerShell or cmd, develop only worked because the MSYS child did the expansion itself, so with this change these break:
That trade-off is the one #4103 documents. #4544, stacked on it, has rtk expand file operands itself when the calling shell didn't, which brings |
Summary
Refs #4256 (the grep/find part; the
head -Nrewrite is a separate question and isn't touched here).grepexpands*,?,[and{in every argument it receives unquoted, even one the user had quoted. std only wraps arguments containing a space or a tab, sortk grep -E '.{0,20}foo' f.txtreachedgrepas.0fooand.20foo:grep: .20foo: No such file or directory.push_child_argnow re-encodes an argument withquote_arg_for_childwhen it holds one of those characters, as it already does for arguments holding a"(Windows: arguments containing a double quote are corrupted when rtk spawns MSYS/Cygwin children (rtk grep, rtk proxy) #3727). Batch shims stay on std's encoding. Native Windows programs parse the quoted form the same way.Test plan
cargo fmt --all && cargo clippy --all-targets -- -D warnings(clean)&& cargo test --bin rtk: 3743 passed, 2 failed.find_cmd::run_from_args_propagates_find_exit_statusandstream::test_read_lines_lossy_preserves_lines_after_invalid_utf8fail the same way ondevelopon this Windows machine.test_needs_child_quoting_flags_quotes_and_msys_glob_characters(all platforms) andtest_child_arg_quotes_msys_glob_patterns(Windows).rtk grep -E '.{0,20}foo' f.txtprinted/usr/bin/grep: .20foo: No such file or directory; after, it prints both matching lines.rtk find . -not -path './x/*'gave the same correct result before and after on this machine, so I haven't claimed thefindcase.Written with help from Claude Opus 5.5.