fix(grep): keep FilePath scope in regex/literal fallback (#756) - #764
Merged
Conversation
The literal/regex fallback rebuilt the query with empty constraints, dropping an explicit inline FilePath scope. In regex mode a top-level alternation then leaked matches into files outside the pinned path. Preserve FilePath constraints in the fallback query. Closes #756
dmtrKovalenko
approved these changes
Aug 12, 2026
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.
Closes #756
Root cause
Two layers. The AI-mode parser splits on whitespace, so regex fragments
^/\*and|^\s*/\*(both contain/+*) are misparsed asGlobconstraints, leaving only----------as grep text. Those bogus globs match nothing, so the constrained search is empty and the literal/regex fallback atcrates/fff-core/src/grep/grep.rs:232rebuilt the query withconstraints: Vec::new(), discarding the user'sFilePath("scope/target.css")scope. In regex mode the raw query is then re-run whole and the top-level|branch^\s*/\* ----------matches/* ----------in every file.Fix
crates/fff-core/src/grep/grep.rs: the fallback now preservesFilePathconstraints (only the swallowed operator/glob tokens are dropped), so a pinned path can't be escaped. Regression test added ingrep_tests.rs.Steps to reproduce
On pre-fix
origin/main:Save
repro.mjsfrom the issue, then:Expected:
actualPathslimited to["scope/target.css"],filteredFileCount/totalFilesSearched= 1.Actual (pre-fix):
{"actualPaths":["outside.css","scope/target.css"],"totalMatched":2,"filteredFileCount":2,"totalFilesSearched":2}How verified
Added e2e regression test reproducing the exact query through the core pipeline (AiGrepConfig + regex mode):
Pre-fix the new test yields
["outside.css","scope/target.css"]; post-fix["scope/target.css"].Automated triage via Gustav. Honk-Honk 🪿