Repository navigation
Description
What happens
On Windows rtk builds every child's command line with one encoder, the MSVCRT/libuv convention that native programs (git.exe, rg.exe, node, dotnet) parse with. MSYS2/Cygwin programs (Git for Windows' grep, find, ls, wc, sed, …) parse the command line with Cygwin's own rules (build_argv / quoted / globify in msys2-runtime winsup/cygwin/dcrt0.cc). The two disagree in one case: inside a quoted argument, Cygwin collapses every \\ to \, while MSVCRT keeps the backslashes that do not precede a quote.
So an argument that has to be quoted (it holds a space or a character MSYS would reinterpret) and contains a run of two or more backslashes not followed by a quote reaches an MSYS child with one backslash of each pair missing. No single encoding is exact for both kinds of child:
- MSYS needs the run doubled.
- MSVCRT needs it as written.
- Moving the run outside the quotes depends on Cygwin's drive-letter heuristic, and fails for one parser or the other.
Evidence
Checked with a Linux harness built from msys2-runtime's real build_argv/quoted/globify and glob.cc (commit c770e1b9), next to an MSVCRT-rule parser. The harness was fed the exact command lines rtk's encoder produces:
| argument | sent | MSYS child receives | native child receives |
|---|---|---|---|
\\( |
"\\(" |
\( |
\\( |
C:\\Temp (x86) |
"C:\\Temp (x86)" |
C:\Temp (x86) |
C:\\Temp (x86) |
a\\b( |
"a\\b(" |
a\b( |
a\\b( |
\\srv\share\(x) |
"\\srv\share\(x)" |
\srv\share\(x) |
\\srv\share\(x) |
C:\a\b "x" |
"C:\a\b \"x\"" |
C:\a\b "x" |
C:\a\b "x" |
Single backslashes (ordinary Windows paths) are exact for both. Only runs of two or more are affected: a UNC path or a regex \\ in an argument that is quoted anyway. For example, rtk grep '\\(' f from PowerShell searches for \( in MSYS grep.
Switching everything to the Cygwin encoding would break native children instead: rtk git commit -m "fix: a\\b" would reach git.exe as a\\\b. That is worse, since git is the most common child.
Proposed
Choose the encoder per child. An MSYS/Cygwin program can be recognised from its executable: its PE import table names msys-2.0.dll or cygwin1.dll.
- MSYS children get the Cygwin-exact encoding.
- Native children keep today's encoding, which is exact for them.
- The choice stays a pure function tested on every platform. Only the PE import scan is Windows-only I/O.
- Cost: reading the import table of the resolved executable, about 1 ms per spawn uncached, less with a per-path cache.
Related
- Windows: arguments containing a double quote are corrupted when rtk spawns MSYS/Cygwin children (rtk grep, rtk proxy) #3727, Windows: MSYS/Cygwin children also lose apostrophes and glob metacharacters, not just double quotes (sequel to #3727) #4102: the MSYS reinterpretation class this encoder addresses.
- refactor(core): make MSYS-safe child argument encoding unforgettable #4103: the
ChildCommandencoder refactor. It keeps today's encoding and documents this limit.
Activity
rtk-wshm-sync-bot commentedon Sep 28, 2026
🔍 Automated Triage
bughighSummary
Windows: single argument encoder mis-serializes backslash runs for MSYS/Cygwin children; needs per-child encoder selection via PE import table detection
📁 Relevant files
src/core/child_command.rssrc/windows/argv_encode.rsSuggested Actions
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
refactor(core): make MSYS-safe child argument encoding unforgettable
KuSh commentedon Oct 9, 2026
UNC paths, as of #4103's current head:
globifyreads\\+ a letter + a later\as a DOS path, so #4103 sends such a path with the\\and the host's first letter before the opening quote. Both parsers then read it as written, a share name holding a space included. The rest of the UNC forms are not DOS paths toglobify, so they still go through the general quoting and keep the limit this issue describes:\\srv\share\(x)\\s"rv\share\(x)"\\srv\my share\x\\s"rv\my share\x"\\srv\share\a\\b(1)\\s"rv\share\a\\b(1)"\\srv\share\a\b(1)\\192.168.1.5\share\x(1)"\\192.168.1.5\share\x(1)"\192.168.1.5\share\x(1)\\192.168.1.5\my share"\\192.168.1.5\my share"\192.168.1.5\my share\\?\C:\x(1)"\\?\C:\x(1)"\?\C:\x(1)\\.\pipe\x(1)"\\.\pipe\x(1)"\.\pipe\x(1)Same oracle as above (msys2-runtime's
build_argv/quoted/globifynext to an MSVCRT parser). So a per-child encoder still has UNC work left: an IP or digit-led host, the\\?\and\\.\device prefixes, and a backslash run inside the path. The Cygwin-exact encoding would double the leading\\inside the quotes for those.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
refactor(core): make MSYS-safe child argument encoding unforgettable
refactor(core): make MSYS-safe child argument encoding unforgettable