Skip to content

fix(windows): quote child arguments containing MSYS globify metacharacters - #4985

Open
CG-5228 wants to merge 1 commit into
rtk-ai:developfrom
CG-5228:fix/windows-msys-child-arg-quoting
Open

CG-5228 wants to merge 1 commit into
rtk-ai:developfrom
CG-5228:fix/windows-msys-child-arg-quoting

Conversation

@CG-5228

@CG-5228 CG-5228 commented Nov 3, 2026

Copy link
Copy Markdown

Summary

  • Fixes rtk grep fails on patterns containing \[ (backslash appears to be dropped) #4737
  • Quote child arguments on Windows in resolved_command (src/core/utils.rs) using cmd_RawArg when an argument contains MSYS/MinGW runtime globify metacharacters (*, ?, [, {, \) and no whitespace/quotes, preventing MSYS2/Git-for-Windows children (git.exe, rg.exe, etc.) from mis-expanding pathspecs like :(exclude)*.lock or regex character classes [0-9] against the working directory.
  • Add unit tests in src/core/utils.rs and tests/windows_child_quoting_test.rs.

Test plan

  • cargo test --lib core::utils::
  • Manual testing: rtk git diff -- ":(exclude)*.lock" argument quoting verified

@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes a Windows bug where MSYS/MinGW child processes (git.exe, rg.exe) misinterpreted globify metacharacters (, ?, [, {, ) in arguments, causing pathspecs like ":(exclude).lock" to be incorrectly expanded against the working directory. The fix quotes such arguments using cmd_RawArg in resolved_command when they contain these metacharacters but no whitespace/quotes, and adds unit and integration tests.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4737


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks for this, and for the integration test with a real MSYS grep, that's the right way to pin it. I ran it natively on Windows (MSVC build, Git for Windows 2.56, throwaway dirs), from both a real Git Bash and PowerShell, against develop and #4260, which takes the same approach with a shorter character list.

It fixes real things. ^\[ and x\|\[a from #4737 now reach grep intact, and rtk grep "it's" file matches. On develop that last one doesn't just miss: MSYS reads the ' as an opening quote that swallows the file name, so grep falls back to stdin and hangs for as long as stdin stays open. The glob cases are fixed too (find . -name '*.tmp' -delete, -name '[ab]*.tmp', grep -E '.{0,20}foo').

Adding \ to the set is what bites, though. Inside quotes an MSYS child halves every run of two or more backslashes (#4326), so arguments that were fine unquoted now get mangled, from Git Bash and PowerShell alike:

develop this PR
rtk grep -n 'C:\\temp' rx.txt matches C:\temp\x no match (exit 1)
rtk grep -n here \\localhost\C$\...\rx.txt matches \localhost\C$\...: No such file or directory
from PowerShell: rtk ls *.txt, rtk grep foo *.txt, rtk wc -l *.txt work No such file or directory

#4103 avoids the first two: it leaves C:\\temp alone and sends a UNC path's leading \\ before the opening quote, which I checked on its branch. The last row it shares with this PR and #4260, since PowerShell and cmd don't expand globs and develop only worked because the MSYS child did it. #4544, stacked on #4103, brings grep *.txt back but not ls or wc yet, and I've raised that gap on #4103. So I'd rather not land this piece on its own. Leaving it open for now while those move.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk grep fails on patterns containing \[ (backslash appears to be dropped)

2 participants