Convert compatible full-regex rules to content-blocking syntax#621
Open
shivaram19 wants to merge 1 commit into
Open
Convert compatible full-regex rules to content-blocking syntax#621shivaram19 wants to merge 1 commit into
shivaram19 wants to merge 1 commit into
Conversation
Fixes brave#156 Currently, full-regex rules are blanket-rejected when converting to content-blocking syntax. However, Safari's content-blocking format does support a subset of regex features: - Literal characters and escaped metacharacters - . (any character) - [...] character classes (including ranges and negation) - ?, +, * quantifiers - (...) capturing groups - ^ and $ anchors This change adds a validator (is_cb_compatible_regex) that checks whether a full-regex rule uses only supported features. Compatible rules are now converted directly; incompatible ones still return FullRegexUnsupported. Test coverage added for supported conversions (simple regex, char classes, groups, anchors) and unsupported rejections (\d, {n}, alternation, non-capturing groups, lookaheads, word boundaries).
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.
Description
Fixes #156
Currently, full-regex rules are blanket-rejected when converting to content-blocking syntax because Safari's support for regex features is much more limited than what ABP syntax allows.
This PR makes it possible to convert some full-regex rules by first verifying that the regex only uses features supported by the content-blocking format.
Supported regex features (now allowed)
\.,\*,\/).(any character)[...]character classes, including ranges[a-z]and negation[^...]?,+,*quantifiers(...)capturing groups^and$anchorsStill unsupported (correctly rejected)
\d,\w,\s,\b, etc. character-class escapes{...}quantified repetition|alternation(?:...),(?=...),(?!...), etc. special groupsChanges
is_cb_compatible_regex()validator insrc/content_blocking.rsTryFrom<NetworkFilter> for CbRuleEquivalentto attempt conversion for compatible full-regex rulesFilterSetintegration test verifying that compatible rules are included and incompatible ones are droppedTest results