Skip to content

Ignore invalid patterns when compiling full-regex sets - #663

Open
KirtiRamchandani wants to merge 1 commit into
brave:masterfrom
KirtiRamchandani:fix/invalid-regex-isolation
Open

Ignore invalid patterns when compiling full-regex sets#663
KirtiRamchandani wants to merge 1 commit into
brave:masterfrom
KirtiRamchandani:fix/invalid-regex-isolation

Conversation

@KirtiRamchandani

Copy link
Copy Markdown

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 RegexSet compilation to fail, which prevents valid patterns in the same set from matching.

Fixes #168.

Root cause

compile_regex returned CompiledRegex::RegexParsingError for the entire set whenever BytesRegexSetBuilder failed. 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 -- --check
  • cargo test -p adblock invalid_complete_regex_does_not_disable_valid_pattern_in_set --lib --features full-regex-handling
  • cargo test -p adblock regex_manager --lib --features full-regex-handling,debug-info
  • cargo test -p adblock --lib --features full-regex-handling
  • cargo test -p adblock --lib
  • cargo clippy -p adblock --features full-regex-handling -- -D warnings
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regex rules nullified by an incorrectly formatted rule

1 participant