Ignore invalid patterns when compiling full-regex sets - #663
Open
KirtiRamchandani wants to merge 1 commit into
Open
Ignore invalid patterns when compiling full-regex sets#663KirtiRamchandani wants to merge 1 commit into
KirtiRamchandani 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.
Problem
Full-regex filters are compiled lazily. When multiple compatible rules are optimized into a single pattern set, one invalid full-regex pattern can cause the whole
RegexSetcompilation to fail, which prevents valid patterns in the same set from matching.Fixes #168.
Root cause
compile_regexreturnedCompiledRegex::RegexParsingErrorfor the entire set wheneverBytesRegexSetBuilderfailed. That is correct for generated simple regexes, but too broad for full-regex filter lists where individual list entries may be unsupported or malformed.Solution
When a full-regex set fails to compile, retry by keeping only patterns that compile individually. The remaining valid patterns are compiled as a single regex or regex set as appropriate. Non-full-regex generated sets keep the previous strict behavior.
Tests
cargo fmt --all -- --checkcargo test -p adblock invalid_complete_regex_does_not_disable_valid_pattern_in_set --lib --features full-regex-handlingcargo test -p adblock regex_manager --lib --features full-regex-handling,debug-infocargo test -p adblock --lib --features full-regex-handlingcargo test -p adblock --libcargo clippy -p adblock --features full-regex-handling -- -D warningsgit diff --check