-
Notifications
You must be signed in to change notification settings - Fork 178
pre-0.12.x => master #574
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
pre-0.12.x => master #574
Changes from all commits
3208116
b3f66ea
6b54aaf
29cf12d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [package] | ||
| name = "adblock" | ||
| version = "0.11.1" | ||
| version = "0.12.0" | ||
| authors = ["Anton Lazarev <[email protected]>", "Andrius Aucinas"] | ||
| edition = "2021" | ||
|
|
||
|
|
@@ -39,6 +39,7 @@ rustc-hash = { version = "1.1.0", default-features = false } | |
| memchr = "2.4" | ||
| base64 = "0.22" | ||
| rmp-serde = "0.15" | ||
| arrayvec = "0.7" | ||
| cssparser = { version = "0.34", optional = true } | ||
| selectors = { version = "0.26", optional = true } | ||
| precomputed-hash = "0.1" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [package] | ||
| name = "adblock-rs" | ||
| version = "0.11.1" | ||
| version = "0.12.0" | ||
| authors = ["Anton Lazarev <[email protected]>", "Andrius Aucinas"] | ||
| edition = "2021" | ||
| license = "MPL-2.0" | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,9 +15,7 @@ use crate::filters::abstract_network::{ | |
| use crate::lists::ParseOptions; | ||
| use crate::regex_manager::RegexManager; | ||
| use crate::request; | ||
| use crate::utils::{self, Hash}; | ||
|
|
||
| pub(crate) const TOKENS_BUFFER_SIZE: usize = 200; | ||
| use crate::utils::{self, Hash, TokensBuffer}; | ||
|
|
||
| /// For now, only support `$removeparam` with simple alphanumeric/dash/underscore patterns. | ||
| static VALID_PARAM: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_\-]+$").unwrap()); | ||
|
|
@@ -312,10 +310,10 @@ pub enum FilterPart { | |
| } | ||
|
|
||
| #[derive(Debug, PartialEq)] | ||
| pub enum FilterTokens { | ||
| pub(crate) enum FilterTokens<'a> { | ||
| Empty, | ||
| OptDomains(Vec<Hash>), | ||
| Other(Vec<Hash>), | ||
| OptDomains(&'a [Hash]), | ||
| Other(&'a [Hash]), | ||
| } | ||
|
|
||
| pub struct FilterPartIterator<'a> { | ||
|
|
@@ -883,19 +881,11 @@ impl NetworkFilter { | |
| ) | ||
| } | ||
|
|
||
| #[deprecated(since = "0.11.1", note = "use get_tokens_optimized instead")] | ||
| pub fn get_tokens(&self) -> Vec<Vec<Hash>> { | ||
| match self.get_tokens_optimized() { | ||
| FilterTokens::OptDomains(domains) => { | ||
| domains.into_iter().map(|domain| vec![domain]).collect() | ||
| } | ||
| FilterTokens::Other(tokens) => vec![tokens], | ||
| FilterTokens::Empty => vec![], | ||
| } | ||
| } | ||
|
|
||
| pub fn get_tokens_optimized(&self) -> FilterTokens { | ||
| let mut tokens: Vec<Hash> = Vec::with_capacity(TOKENS_BUFFER_SIZE); | ||
| pub(crate) fn get_tokens<'a>( | ||
| &'a self, | ||
| tokens_buffer: &'a mut TokensBuffer, | ||
| ) -> FilterTokens<'a> { | ||
| tokens_buffer.clear(); | ||
|
|
||
| // If there is only one domain and no domain negation, we also use this | ||
| // domain as a token. | ||
|
|
@@ -905,7 +895,7 @@ impl NetworkFilter { | |
| { | ||
| if let Some(domains) = self.opt_domains.as_ref() { | ||
| if let Some(domain) = domains.first() { | ||
| tokens.push(*domain) | ||
| tokens_buffer.push(*domain); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -918,7 +908,7 @@ impl NetworkFilter { | |
| (self.is_plain() || self.is_regex()) && !self.is_right_anchor(); | ||
| let skip_first_token = self.is_right_anchor(); | ||
|
|
||
| utils::tokenize_filter_to(f, skip_first_token, skip_last_token, &mut tokens); | ||
| utils::tokenize_filter_to(f, skip_first_token, skip_last_token, tokens_buffer); | ||
| } | ||
| } | ||
| FilterPart::AnyOf(_) => (), // across AnyOf set of filters no single token is guaranteed to match to a request | ||
|
|
@@ -928,45 +918,55 @@ impl NetworkFilter { | |
| // Append tokens from hostname, if any | ||
| if !self.mask.contains(NetworkFilterMask::IS_HOSTNAME_REGEX) { | ||
| if let Some(hostname) = self.hostname.as_ref() { | ||
| utils::tokenize_to(hostname, &mut tokens); | ||
| utils::tokenize_to(hostname, tokens_buffer); | ||
| } | ||
| } else if let Some(hostname) = self.hostname.as_ref() { | ||
| // Find last dot to tokenize the prefix | ||
| let last_dot_pos = hostname.rfind('.'); | ||
| if let Some(last_dot_pos) = last_dot_pos { | ||
| utils::tokenize_to(&hostname[..last_dot_pos], &mut tokens); | ||
| utils::tokenize_to(&hostname[..last_dot_pos], tokens_buffer); | ||
| } | ||
| } | ||
|
|
||
| if tokens.is_empty() && self.mask.contains(NetworkFilterMask::IS_REMOVEPARAM) { | ||
| if tokens_buffer.is_empty() && self.mask.contains(NetworkFilterMask::IS_REMOVEPARAM) { | ||
| if let Some(removeparam) = &self.modifier_option { | ||
| if VALID_PARAM.is_match(removeparam) { | ||
| utils::tokenize_to(&removeparam.to_ascii_lowercase(), &mut tokens); | ||
| utils::tokenize_to(&removeparam.to_ascii_lowercase(), tokens_buffer); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // If we got no tokens for the filter/hostname part, then we will dispatch | ||
| // this filter in multiple buckets based on the domains option. | ||
| if tokens.is_empty() && self.opt_domains.is_some() && self.opt_not_domains.is_none() { | ||
| if tokens_buffer.is_empty() && self.opt_domains.is_some() && self.opt_not_domains.is_none() | ||
| { | ||
| if let Some(opt_domains) = self.opt_domains.as_ref() { | ||
| if !opt_domains.is_empty() { | ||
| return FilterTokens::OptDomains(opt_domains.clone()); | ||
| return FilterTokens::OptDomains(opt_domains); | ||
| } | ||
| } | ||
| FilterTokens::Empty | ||
| } else { | ||
| // Add optional token for protocol | ||
| if self.for_http() && !self.for_https() { | ||
| tokens.push(utils::fast_hash("http")); | ||
| tokens_buffer.push(utils::fast_hash("http")); | ||
| } else if self.for_https() && !self.for_http() { | ||
| tokens.push(utils::fast_hash("https")); | ||
| tokens_buffer.push(utils::fast_hash("https")); | ||
| } | ||
|
|
||
| // Remake a vector to drop extra capacity. | ||
| let mut t = Vec::with_capacity(tokens.len()); | ||
| t.extend(tokens); | ||
| FilterTokens::Other(t) | ||
| FilterTokens::Other(tokens_buffer.as_slice()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub(crate) fn matches_test(&self, request: &request::Request) -> bool { | ||
| let filter_set = crate::FilterSet::new_with_rules(vec![self.clone()], vec![], true); | ||
| let engine = crate::Engine::from_filter_set(filter_set, true); | ||
|
|
||
| if self.is_exception() { | ||
| engine.check_network_request_exceptions(request) | ||
| } else { | ||
| engine.check_network_request(request).matched | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -986,35 +986,8 @@ impl fmt::Display for NetworkFilter { | |
| } | ||
| } | ||
|
|
||
| pub trait NetworkMatchable { | ||
| pub(crate) trait NetworkMatchable { | ||
| fn matches(&self, request: &request::Request, regex_manager: &mut RegexManager) -> bool; | ||
|
|
||
| #[cfg(test)] | ||
| fn matches_test(&self, request: &request::Request) -> bool; | ||
| } | ||
|
|
||
| impl NetworkMatchable for NetworkFilter { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can also make
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I also removed unused |
||
| fn matches(&self, request: &request::Request, regex_manager: &mut RegexManager) -> bool { | ||
| use crate::filters::network_matchers::{ | ||
| check_excluded_domains, check_included_domains, check_options, check_pattern, | ||
| }; | ||
| check_options(self.mask, request) | ||
| && check_included_domains(self.opt_domains.as_deref(), request) | ||
| && check_excluded_domains(self.opt_not_domains.as_deref(), request) | ||
| && check_pattern( | ||
| self.mask, | ||
| self.filter.iter(), | ||
| self.hostname.as_deref(), | ||
| (self as *const NetworkFilter) as u64, | ||
| request, | ||
| regex_manager, | ||
| ) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| fn matches_test(&self, request: &request::Request) -> bool { | ||
| self.matches(request, &mut RegexManager::default()) | ||
| } | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.