Repository navigation
searcher: fix runaway output with -v, -m, and -A combined - #3602
Open
tanveer-arch wants to merge 1 commit into
Open
tanveer-arch wants to merge 1 commit into
tanveer-arch wants to merge 1 commit into
Conversation
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.
Fixes #3593.
Combining
-v,-m, and-Acurrently bugs out and prints the entire rest of the input as matches, even lines that actually match the pattern.The root issue is how the limit's
Nonereturn gets handled under-v:shortest_matchreturnsNone. Under-v, this reads as an inverted match. The line gets sunk as a match, which resets the after-context counter back to full, so the stop condition is never reached.false, the code treated it as abreak, which incorrectly ran the trailing after-context and called the sink again for those same lines.The fix handles this across three parts in
crates/searcher/src/searcher/core.rs:is_match). Matching lines are sunk as after-context. Non-matching lines are sunk as matches, but we just consume one line of after-context instead of resetting it, and we don't count it toward the limit. (If no after-context is owed, e.g.--passthru, it falls through to the old behavior).true(notfalse) so the caller still runs the trailing context.false, we stop entirely instead of breaking to the trailing context.falsenow strictly means the sink rejected it.Testing & Validation:
crates/searcher/src/searcher/glue.rs(slow/fast slices + a chunked-reader simulating a two-read pipe) and integration testr3593intests/regression.rs.178cc027e2and pass with this fix.grep-searcher79/79 (+ 1 doctest), integration 333/333, 0 total failures.cargo fmt, 0 new clippy warnings (37 pre-existing) on1.99.1.