Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/filters/cosmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ impl CosmeticFilter {
hostname.len()
};
let location = &hostname[start..end];
// Skip wildcard (*) - it matches all domains
if location == "*" {
return None;
}
// AdGuard regex syntax
if location.starts_with('/') {
return Some((CosmeticFilterLocationType::Unsupported, part));
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") {
7671576097086431151
9113803688770546221
} else {
7220740598028920672
15343284834809453004
};

assert_eq!(hash(&data), expected_hash, "{HASH_MISMATCH_MSG}");
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/filters/cosmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,53 @@ mod parse_tests {
);
}

#[test]
fn wildcard_support() {
// Wildcard for scriptlet injection (issue #582)
check_parse_result(
r#"*##+js(test-scriptlet.js)"#,
CosmeticFilterBreakdown {
selector: SelectorType::PlainCss(r#"test-scriptlet.js"#.to_string()),
script_inject: true,
..Default::default()
},
);
check_parse_result(
r#"*##+js(test-scriptlet.js, arg1, arg2)"#,
CosmeticFilterBreakdown {
selector: SelectorType::PlainCss(r#"test-scriptlet.js, arg1, arg2"#.to_string()),
script_inject: true,
..Default::default()
},
);
// Wildcard for regular cosmetic filters
check_parse_result(
r#"*##.ad-banner"#,
CosmeticFilterBreakdown {
selector: SelectorType::PlainCss(r#".ad-banner"#.to_string()),
..Default::default()
},
);
// Wildcard combined with other domains
check_parse_result(
r#"*,example.com##.ad-banner"#,
CosmeticFilterBreakdown {
selector: SelectorType::PlainCss(r#".ad-banner"#.to_string()),
hostnames: sort_hash_domains(vec!["example.com"]),
..Default::default()
},
);
check_parse_result(
r#"example.com,*##+js(test-scriptlet.js)"#,
CosmeticFilterBreakdown {
selector: SelectorType::PlainCss(r#"test-scriptlet.js"#.to_string()),
hostnames: sort_hash_domains(vec!["example.com"]),
script_inject: true,
..Default::default()
},
);
}

#[test]
fn entities() {
check_parse_result(
Expand Down