grep: detect format flags bundled inside short-flag clusters#2544
Open
EtaCassiopeia wants to merge 1 commit into
Open
grep: detect format flags bundled inside short-flag clusters#2544EtaCassiopeia wants to merge 1 commit into
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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