brave / brave/adblock-rust

Regex rules nullified by an incorrectly formatted rule

Open
#168 0 comments 0 reactions 1 assignee Claimed by @antonok-edm View on GitHub
bug
Dominant language
Rust
Stars
2.8k
Forks
250
Avg merge
1d 16h
Merged PRs (30d)
6

Description

The following test case currently fails:

```rust
#[test]
fn valid_invalid_regex() {
let filters = vec![
String::from(r#"/^https:\/\/b\.com/"#),
String::from(r#"/^\=/"#),
];

let engine = Engine::from_rules_debug(&filters, FilterFormat::Standard);

assert!(engine.check_network_urls("https://b.com", "https://c.com", "script").matched);
}
```

The first filter works correctly when isolated, but as soon as the second filter is added, it no longer matches any requests.

It appears that this is due to the fact that the second rule is an incorrectly formatted regex (the `=` character does not need to be escaped). Regex rules are lazily compiled, so this issue is not caught immediately. Later on, the regexes get compiled into an `AnyOf` regex rule, but the entire rule is invalid because of the presence of the second rule and it produces a `CompiledRegex::RegexParsingError`.

Either at parsing or compile time, these filters should be evaluated for validity and removed if necessary.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.