Repository navigation
grep: detect format flags bundled inside short-flag clusters - #2544
EtaCassiopeia wants to merge 1 commit into
Conversation
has_format_flag only matched exact tokens like "-l", but extract_pattern_path merges boolean short flags into one cluster (e.g. `-rln` becomes `-ln` after stripping `r`). A bundled -l/-c/-o/-L/-Z never matched, so grep_cmd tried to NUL-parse rg's output as if it were normal match lines, even though -l/-c/etc. change rg's output shape entirely. The result was a false "0 matches" instead of the real answer. Now has_format_flag also scans the individual letters of a short-flag cluster, so a bundled format flag correctly falls through to the existing passthrough path.
|
Confirmed on WSL2 (Ubuntu 24.04) / Linux x86_64, rtk 0.42.4, invoked via the Claude Code auto-rewrite hook — a third platform alongside the macOS report in #2647 and the Linux/0.42.1 report in #2563. Traced independently to exactly the cause described here: Minimal repro: Real-world impact matched #2563 almost exactly: the false zero read as an LLM hallucination and nearly triggered a destructive "correction" (concluding correct, existing content did not exist). The |
|
Follow-up: this is already fixed on |
|
Thanks for digging into the bundled-cluster case and writing the repro. This landed by way of #2550 (merged 2026-06-23), which rewrote grep into src/cmds/system/search.rs; its has_format_flag scans every letter of a short cluster for c/l/L/o/q/b/Z/z and matches long flags against an explicit list, so -ln and -rln now route to passthrough exactly as you described. Develop also carries unit tests for -rl/-rc/-rq/-rln/-cr and an end-to-end -rln test citing #2543, so the coverage your patch added is present too. Running the repro on develop lists the matching files instead of reporting 0 matches. Closing as covered, but please comment or reopen if you see a flag shape that still slips through. |
Follow-up to #2543 — this fixes the second part of it.
has_format_flagchecksextra_argsfor things like-l/-c/-oso it knows to skip the usual match-line parsing and just pass rg's output straight through (since those flags change rg's output format entirely). That check only matches exact tokens though, andextract_pattern_pathmerges plain boolean short flags into one combined token before they get here — so-rlnbecomes-lnafterris stripped, and-lnnever matches-lexactly.End result: something like
rtk grep -rln pattern pathruns rg with-lcorrectly, but then tries to parse the (now filenames-only) output as if it were normalfile:line:contentmatches, finds nothing that fits that shape, and reports "0 matches" even when there clearly are matches. That's worse than just erroring, since it looks identical to a real empty result.Fix is small —
has_format_flagnow also scans the individual letters of a short cluster (long flags and exact single-flag matches are unaffected). Added a few tests for the clustered case plus one to make sure long flags like--ignore-casedon't get walked character-by-character by mistake.Tested locally:
rtk grep -rln pattern pathnow correctly falls through to passthrough and shows the real file list instead of "0 matches in 0 files"rtk grep -rn pattern pathunaffectedcloses #2543