Skip to content

Commit

Permalink
remove Engine::filter_exists
Browse files Browse the repository at this point in the history
It's not very practical and probably doesn't do what you expected,
anyways.
  • Loading branch information
antonok-edm committed Aug 10, 2023
1 parent 57a2e03 commit 3192576
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
16 changes: 0 additions & 16 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,6 @@ impl Engine {
self.blocker.get_csp_directives(request)
}

/// Check if a given filter has been previously added to this `Engine`.
///
/// Note that only network filters are currently supported by this method.
pub fn filter_exists(&self, filter: &str) -> bool {
use crate::filters::network::NetworkFilter;
let filter_parsed = NetworkFilter::parse(filter, false, Default::default());
match filter_parsed.map(|f| self.blocker.filter_exists(&f)) {
Ok(exists) => exists,
Err(_e) => {
#[cfg(test)]
eprintln!("Encountered unparseable filter when checking for filter existence: {:?}", _e);
false
}
}
}

/// Sets this engine's tags to be _only_ the ones provided in `tags`.
///
/// Tags can be used to cheaply enable or disable network rules with a corresponding `$tag`
Expand Down
16 changes: 7 additions & 9 deletions tests/legacy_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,15 +686,13 @@ mod legacy_misc_tests {
let mut engine2 = Engine::new(false);
engine2.deserialize(&serialized).unwrap();

assert!(engine.filter_exists("||googlesyndication.com$third-party"));
assert!(engine2.filter_exists("||googlesyndication.com$third-party"));
assert!(!engine.filter_exists("||googleayndication.com$third-party"));
assert!(!engine2.filter_exists("||googleayndication.com$third-party"));

assert!(engine.filter_exists("@@||googlesyndication.ca"));
assert!(engine2.filter_exists("@@||googlesyndication.ca"));
assert!(!engine.filter_exists("googlesyndication.ca"));
assert!(!engine2.filter_exists("googlesyndication.ca"));
assert!(engine.check_network_request(&Request::new("https://googlesyndication.com/script.js", "https://example.com", "script").unwrap()).matched);
assert!(engine2.check_network_request(&Request::new("https://googlesyndication.com/script.js", "https://example.com", "script").unwrap()).matched);
assert!(!engine.check_network_request(&Request::new("https://googleayndication.com/script.js", "https://example.com", "script").unwrap()).matched);
assert!(!engine2.check_network_request(&Request::new("https://googleayndication.com/script.js", "https://example.com", "script").unwrap()).matched);

assert!(!engine.check_network_request(&Request::new("https://googlesyndication.ca/script.js", "https://example.com", "script").unwrap()).matched);
assert!(!engine2.check_network_request(&Request::new("https://googlesyndication.ca/script.js", "https://example.com", "script").unwrap()).matched);
}

#[test]
Expand Down

0 comments on commit 3192576

Please sign in to comment.