Fix regex filter parsing when pattern contains $ end-anchor#608
Open
0b0d3 wants to merge 2 commits intobrave:masterfrom
Open
Fix regex filter parsing when pattern contains $ end-anchor#6080b0d3 wants to merge 2 commits intobrave:masterfrom
0b0d3 wants to merge 2 commits intobrave:masterfrom
Conversation
Regex filters like `/pattern$/` use `$` as a regex end-of-string anchor, but the parser always treated the last `$` as the options separator. This caused filters like `/\.json$/` to fail with UnrecognisedOption, and filters like `/regex$/$xhr,match-case` to lose the `$` anchor from their pattern. The fix tries each `$` from right to left, but only falls back to the next candidate when the pattern to the left looks like a regex (delimited by `/`). Non-regex filters still propagate option parse errors immediately. Fixes brave#257 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
approach looks good, this is basically what i described in my comment above. logic is clean and the tests cover the key cases. one small thing: the otherwise lgtm |
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.
Summary
Fixes #257
/pattern$/use$as a regex end-of-string anchor, but the parser always treated the rightmost$as the options separator/\.json$/to fail withUnrecognisedOption, and filters like/^https?:\/\/[a-z]{8,15}\.top\/[a-z]{4,}\.json$/$xhr,3p,match-caseto lose the$anchor from their pattern$from right to left, but only falls back to the next candidate when the pattern to the left looks like a regex (delimited by/). Non-regex filters still propagate option parse errors immediatelyChanges
src/filters/abstract_network.rs: Replace singlefind_char_reversewith a loop that tries$candidates right-to-left, with regex-awareness to avoid false fallbackstests/unit/filters/network.rs: Added 3 test cases covering regex with$anchor + options, regex with$anchor alone, and regex without$anchortests/unit/blocker.rs: Updated easylist filter count (4 more filters now correctly parsed)tests/unit/engine.rs: Updated serialization hashes to reflect the new parsing behaviorTest plan
css-validationfeature)$end-anchor and options parses correctly$end-anchor and no options parses correctly$anchor and options still works🤖 Generated with Claude Code