fix(rg): reject empty pattern with --only-matching#1649
Open
chaliy wants to merge 1 commit into
Open
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 150a0ad | Commit Preview URL | May 23 2026, 09:15 AM |
d2d3a6b to
a2f802a
Compare
Prevent resource-exhaustion triggered by rg -o/--only-matching with an empty pattern, which produces zero-width matches at every UTF-8 boundary and can amplify builtin output allocations before interpreter truncation. Add a parse-time check in RgOptions::parse that returns Error::Execution when --only-matching is enabled and any provided pattern is empty.
a2f802a to
150a0ad
Compare
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.
Motivation
rg -o/--only-matchingwith an empty pattern, which produces zero-width matches at every UTF-8 boundary and can amplify builtin output allocations before interpreter truncation.Description
RgOptions::parse(incrates/bashkit/src/builtins/rg.rs) to returnErr(Error::Execution("rg: empty pattern is not allowed with --only-matching"))when--only-matchingis enabled and any provided pattern is empty, and add a unit testtest_rg_only_matching_rejects_empty_patternto cover-o -e ''.Testing
cargo test -p bashkit rg_only_matchingand the targeted tests includingtest_rg_only_matching_rejects_empty_patternpassed.Codex Task