Skip to content
Merged
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
7 changes: 7 additions & 0 deletions src/filters/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ pub enum FilterPart {
AnyOf(Vec<String>),
}

#[derive(Debug, PartialEq)]
pub enum FilterTokens {
Empty,
OptDomains(Vec<Hash>),
Expand Down Expand Up @@ -929,6 +930,12 @@ impl NetworkFilter {
if let Some(hostname) = self.hostname.as_ref() {
utils::tokenize_to(hostname, &mut tokens);
}
} 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);
}
}

if tokens.is_empty() && self.mask.contains(NetworkFilterMask::IS_REMOVEPARAM) {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ mod tests {
);
}
let expected_hash: u64 = if cfg!(feature = "css-validation") {
9439492009815519037
15545091389304905433
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to update ADBLOCK_RUST_DAT_VERSION, because the matching logic isn't changed. Tt's only a optimization how we store rules. The current .dat files can be used as is.

} else {
14803842039735157685
543362704487480180
};

assert_eq!(hash(&data), expected_hash, "{HASH_MISMATCH_MSG}");
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/filters/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,4 +1186,17 @@ mod parse_tests {
defaults.opt_domains = Some(vec![utils::fast_hash("auth.wi-fi.ru")]);
assert_eq!(defaults, NetworkFilterBreakdown::from(&filter));
}

#[test]
fn test_simple_pattern_tokenization() {
let rule = "||some.primewire.c*/sw$script,1p";
let filter = NetworkFilter::parse(rule, true, ParseOptions::default()).unwrap();
assert_eq!(
filter.get_tokens_optimized(),
FilterTokens::Other(vec![
utils::fast_hash("some"),
utils::fast_hash("primewire")
])
);
}
}
Loading