Repository navigation
Description
#3727 / #3728 fixed the case where an argument contains a ". That is one of several characters Cygwin's command-line parser reinterprets when the parent is a native Win32 process such as rtk.exe.
From winsup/cygwin/dcrt0.cc:
build_argvis called withwinshell = NOTSTATE (myself, PID_CYGPARENT) && allow_glob, which is true for a native parent like rtk (line 909).- With
winshelltrue,build_argvtestsif (*cmd != '"' && (!winshell || *cmd != '\''))— so'is a quote character too. - Every non-
argv[0]word then goes throughglobify, which bails only when*word != '~' && strpbrk(word, "?*[\"\'(){}") == NULL, and otherwise runsglob(pattern, GLOB_TILDE|GLOB_NOCHECK|GLOB_BRACE|GLOB_QUOTE, …).
Verified against a port of Cygwin's own build_argv/quoted/globify:
rtk grep "it's" file.txt → MSYS grep receives: its
rtk grep "don't" file.txt → MSYS grep receives: dont
The apostrophe is silently dropped and grep searches for the wrong string — a wrong answer, not an error. This is identical before and after #3728, i.e. pre-existing; #3728 correctly scoped itself to the double-quote case.
Confirmed on a real MSYS box — see this comment (rtk 0.50.0, Windows 11, Git for Windows 2.55.0, passing each argument to MSYS printf and to a native python.exe as the control). GLOB_BRACE does split a single argument such as x{1,2} into two argv entries, destroying a bounded-repetition regex and adding a bogus file operand.
That run also shows a consequence missing from the list above: * and ? are glob-expanded against the child's working directory, so a*b arrives as the names of whatever files happen to match. A regex such as a.*b or v[0-9]?, or any sed/awk program containing *, is silently replaced by file names, and the command still exits 0. GLOB_QUOTE strips the backslashes from #\[test\] the same way, so grep -c '#\[test\]' counts 0 where a direct call counts 2. The native child receives every argument byte-for-byte, so this is specific to MSYS/Cygwin children — which is the case for encoding per child (#4326).
Why this is not a one-line widening. The obvious fix is to widen push_child_arg's trigger from s.contains('"') to also cover ', ?*[(){} and a leading ~, since globify backslash-escapes everything inside a quoted region before globbing. But wrapping an argument also suppresses child-side globbing. That is correct for search.rs patterns (the caller's shell already globbed) and a real behaviour change for ls/find path operands invoked from cmd.exe, where no parent shell globbed. So the trigger set and the glob question need deciding together, per call site — worth its own PR.
Note libuv has the same gap, so "matches libuv" is not the right bar for this one.
Follow-up from the review of #3728.
Activity
rtk-wshm-sync-bot commentedon Sep 18, 2026
🔍 Automated Triage
bughighSummary
On Windows, MSYS/Cygwin children silently drop apostrophes and glob metacharacters from native-parent-passed args (not just double quotes), producing wrong results without error; fix requires per-call-site decisions about quoting vs. child-side globbing, and GLOB_BRACE arg-splitting risk needs verification on real MSYS.
Triaged automatically by wshm · This is an automated analysis, not a human review.
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
30 remaining items
fix(search): wire the engine's stdin from what the invocation names
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
SNComrade commentedon Nov 12, 2026
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable
KuSh commentedon Nov 17, 2026
Thanks @SNComrade. #4103 covers this case: an argument that starts with
@is quoted before an MSYS/Cygwin child sees it, and the child only reads a response file for an unquoted@.rtk bypassandrtk grepboth start their child that way, so'@RTK.md'reaches it as written.refactor(core): make MSYS-safe child argument encoding unforgettable
stevebeauge commentedon Nov 23, 2026
Another instance of the
GLOB_QUOTEcase, still present on rtk 1.2.1 (WinGetrtk-ai.rtk), Windows 11, Git Bash (Git for Windows grep): a regex escape such as\sis dropped as soon as the same argument contains(or[, so grep searches for a literals.Same result without
-Eand with a tab instead of a space. Not tested on Linux; the mechanism is specific to MSYS/Cygwin children.KuSh commentedon Nov 23, 2026
Thanks @stevebeauge. #4103 covers this one too: an argument that holds
(,[or another characterglobifyreacts to now reaches an MSYS/Cygwin child wrapped in quotes, soglobifyno longer reads\sas an escape, and grep getsa\s(b|c)anda\s[b]as typed. It's the same mechanism as the^\[TAG\]case above. One limit remains inside the quotes: a run of two or more backslashes (a\\s() is still halved by the MSYS child, tracked in #4326.refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable