Skip to content

Windows: arguments containing a double quote are corrupted when rtk spawns MSYS/Cygwin children (rtk grep, rtk proxy) #3727

Closed

Description

@esidorenko-sl

rtk 0.45.0 and 0.46.0. Windows 11 (build 26200), Git Bash, Git for Windows 2.55.0, GNU grep 3.0.

Any argument that contains a " but no space or tab reaches an MSYS/Cygwin child process corrupted. stderr stays empty, so it looks like a legitimate "no matches".

Repro

$ printf '%s\n' '{"type":"a"}' '{"role":"b"}' > q.jsonl

$ grep -c '"type"' q.jsonl
1

$ rtk grep -c '"type"' q.jsonl
0
$ echo $?
1

$ rtk rg -c '"type"' q.jsonl
1

rtk grep '"type"' q.jsonl (without -c) prints nothing and exits 1 as well. It is not specific to grep, rtk proxy corrupts the argument too:

$ rtk proxy printf '[%s]' 'a"b'
[a\b]        # expected [a"b]
$ rtk proxy printf '[%s]' 'a"b c'
[a"b c]      # correct, because the argument now contains a space

Cause

On Windows std::process::Command wraps an argument in double quotes only when it contains a space or a tab. An argument like a"b therefore lands on the child's raw command line as bare a\"b. MSVCRT/UCRT children decode that; Cygwin/MSYS children do not, so the quote turns into a backslash and adjacent arguments merge. On Windows the grep that which resolves is the Git for Windows MSYS binary, which is why rtk grep breaks while rtk rg (native ripgrep) and rtk git (native git.exe) are fine.

Isolated on one and the same grep.exe, same logical argument, only the wrapping quotes differing:

raw command line   grep -c \"type\" q.jsonl       gives 0, exit 1
raw command line   grep -c "\"type\"" q.jsonl     gives 1, exit 0

Native children accept both forms, so quoting the way libuv does (wrap whenever the argument is empty or contains a space, a tab or a ") fixes MSYS children with no behaviour change for native ones. It needs CommandExt::raw_arg at the spawn sites; today the callers of resolved_command in src/core/utils.rs all use plain .arg().

Happy to send a PR against develop if you want it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions