Skip to content

$all #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged

$all #460

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,14 @@ mod tests {
}
}

#[test]
fn explicit_all() {
let engine = Engine::from_rules_debug(["*$all,domain=rarvinzp.click|ytrqcxat.click"], Default::default());
for content_type in ["script", "document", "subdocument", "font", "xmlhttprequest"] {
assert!(engine.check_network_request(&Request::new("https://example.com", "https://rarvinzp.click", content_type).unwrap()).matched);
}
}

#[test]
fn generichide() {
let filters = [
Expand Down
9 changes: 8 additions & 1 deletion src/filters/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum NetworkFilterError {
NegatedGenericHide,
#[error("negated document")]
NegatedDocument,
#[error("negated all")]
NegatedAll,
#[error("generichide without exception")]
GenericHideWithoutException,
#[error("empty redirection")]
Expand Down Expand Up @@ -283,6 +285,7 @@ enum NetworkFilterOption {
XmlHttpRequest(bool),
Websocket(bool),
Font(bool),
All,
}

impl NetworkFilterOption {
Expand All @@ -298,7 +301,8 @@ impl NetworkFilterOption {
| Self::Subdocument(..)
| Self::XmlHttpRequest(..)
| Self::Websocket(..)
| Self::Font(..))
| Self::Font(..)
| Self::All)
}

pub fn is_redirection(&self) -> bool {
Expand Down Expand Up @@ -457,6 +461,8 @@ fn parse_filter_options(raw_options: &str) -> Result<Vec<NetworkFilterOption>, N
("xmlhttprequest", negated) | ("xhr", negated) => NetworkFilterOption::XmlHttpRequest(!negated),
("websocket", negated) => NetworkFilterOption::Websocket(!negated),
("font", negated) => NetworkFilterOption::Font(!negated),
("all", true) => return Err(NetworkFilterError::NegatedAll),
("all", false) => NetworkFilterOption::All,
(_, _) => return Err(NetworkFilterError::UnrecognisedOption),
});
}
Expand Down Expand Up @@ -639,6 +645,7 @@ impl NetworkFilter {
NetworkFilterOption::XmlHttpRequest(enabled) => apply_content_type!(FROM_XMLHTTPREQUEST, enabled),
NetworkFilterOption::Websocket(enabled) => apply_content_type!(FROM_WEBSOCKET, enabled),
NetworkFilterOption::Font(enabled) => apply_content_type!(FROM_FONT, enabled),
NetworkFilterOption::All => apply_content_type!(FROM_ALL_TYPES, true),
}
});
}
Expand Down