Skip to content

Commit 67b7b70

Browse files
committed
support $all
this won't include `popup`, `inline-script`, or `inline-font` for now due to lack of support for the individual options, but we may as well convert `$all` into all supported types.
1 parent d56be21 commit 67b7b70

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/filters/abstract_network.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub(crate) enum NetworkFilterOption {
5959
XmlHttpRequest(bool),
6060
Websocket(bool),
6161
Font(bool),
62+
All,
6263
}
6364

6465
impl NetworkFilterOption {
@@ -77,6 +78,7 @@ impl NetworkFilterOption {
7778
| Self::XmlHttpRequest(..)
7879
| Self::Websocket(..)
7980
| Self::Font(..)
81+
| Self::All
8082
)
8183
}
8284

@@ -249,6 +251,8 @@ fn parse_filter_options(raw_options: &str) -> Result<Vec<NetworkFilterOption>, N
249251
}
250252
("websocket", negated) => NetworkFilterOption::Websocket(!negated),
251253
("font", negated) => NetworkFilterOption::Font(!negated),
254+
("all", true) => return Err(NetworkFilterError::NegatedAll),
255+
("all", false) => NetworkFilterOption::All,
252256
(_, _) => return Err(NetworkFilterError::UnrecognisedOption),
253257
});
254258
}

src/filters/network.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub enum NetworkFilterError {
4242
NegatedGenericHide,
4343
#[error("negated document")]
4444
NegatedDocument,
45+
#[error("negated all")]
46+
NegatedAll,
4547
#[error("generichide without exception")]
4648
GenericHideWithoutException,
4749
#[error("empty redirection")]
@@ -570,6 +572,7 @@ impl NetworkFilter {
570572
apply_content_type!(FROM_WEBSOCKET, enabled)
571573
}
572574
NetworkFilterOption::Font(enabled) => apply_content_type!(FROM_FONT, enabled),
575+
NetworkFilterOption::All => apply_content_type!(FROM_ALL_TYPES, true),
573576
}
574577
});
575578
}

tests/unit/engine.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,34 @@ mod tests {
444444
}
445445
}
446446

447+
#[test]
448+
fn explicit_all() {
449+
let engine = Engine::from_rules_debug(
450+
["*$all,domain=rarvinzp.click|ytrqcxat.click"],
451+
Default::default(),
452+
);
453+
for content_type in [
454+
"script",
455+
"document",
456+
"subdocument",
457+
"font",
458+
"xmlhttprequest",
459+
] {
460+
assert!(
461+
engine
462+
.check_network_request(
463+
&Request::new(
464+
"https://example.com",
465+
"https://rarvinzp.click",
466+
content_type
467+
)
468+
.unwrap()
469+
)
470+
.matched
471+
);
472+
}
473+
}
474+
447475
#[test]
448476
fn generichide() {
449477
let filters = [

0 commit comments

Comments
 (0)