Skip to content

Commit

Permalink
Update adblock-rust to v0.8.2 (uplift to 1.60.x) (#20643)
Browse files Browse the repository at this point in the history
Uplift of #20614 (squashed) to beta
  • Loading branch information
brave-builds authored Oct 24, 2023
1 parent a493e5c commit 8e4c4ca
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion components/brave_shields/adblock/rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
adblock = { version = "0.8.1", default-features = false, features = ["full-regex-handling", "regex-debug-info", "css-validation"] }
adblock = { version = "0.8.2", default-features = false, features = ["full-regex-handling", "regex-debug-info", "css-validation"] }
cxx = "1.0"
serde_json = "1.0"
thiserror = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions third_party/rust/adblock/v0_8/README.chromium
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Name: adblock
URL: https://crates.io/crates/adblock
Description: Native Rust module for Adblock Plus syntax (e.g. EasyList, EasyPrivacy) filter parsing and matching.
Version: 0.8.1
Version: 0.8.2
Security Critical: no
License: Mozilla Public License 2.0
Revision: bc39fa8a52bc96db18e8c14de73ed63d883a7b09
Revision: 949a6e159a7289332da1df966d4565876adc5c3c
2 changes: 1 addition & 1 deletion third_party/rust/adblock/v0_8/crate/.cargo_vcs_info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"git": {
"sha1": "bc39fa8a52bc96db18e8c14de73ed63d883a7b09"
"sha1": "949a6e159a7289332da1df966d4565876adc5c3c"
},
"path_in_vcs": ""
}
6 changes: 3 additions & 3 deletions third_party/rust/adblock/v0_8/crate/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion third_party/rust/adblock/v0_8/crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[package]
edition = "2021"
name = "adblock"
version = "0.8.1"
version = "0.8.2"
authors = [
"Andrius Aucinas <aaucinas@brave.com>",
"Anton Lazarev <alazarev@brave.com>",
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/adblock/v0_8/crate/Cargo.toml.orig

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
Expand Up @@ -7,7 +7,7 @@ use adblock::request::Request;
use adblock::resources::ResourceStorage;

const DEFAULT_LISTS_URL: &str =
"https://raw.githubusercontent.com/brave/adblock-resources/master/filter_lists/default.json";
"https://raw.githubusercontent.com/brave/adblock-resources/master/filter_lists/list_catalog.json";

async fn get_all_filters() -> Vec<String> {
use futures::FutureExt;
Expand Down
18 changes: 16 additions & 2 deletions third_party/rust/adblock/v0_8/crate/src/cosmetic_filter_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ impl CosmeticFilterCache {
let mut script_injections = HashMap::<&str, PermissionMask>::new();
let mut exceptions = HashSet::new();

let mut except_all_scripts = false;

let hashes: Vec<&Hash> = request_entities.iter().chain(request_hostnames.iter()).collect();

fn populate_set(hash: &Hash, source_bin: &HostnameFilterBin<String>, dest_set: &mut HashSet<String>) {
Expand Down Expand Up @@ -308,9 +310,16 @@ impl CosmeticFilterCache {
prune_set(hash, &self.specific_rules.unremove, &mut remove_selectors);
// same logic but not using prune_set since strings are unowned, (see above)
if let Some(s) = self.specific_rules.uninject_script.get(hash) {
s.iter().for_each(|s| {
for s in s {
if s.is_empty() {
except_all_scripts = true;
script_injections.clear();
}
if except_all_scripts {
continue;
}
script_injections.remove(s.as_str());
});
}
}

prune_map(hash, &self.specific_rules.unstyle, &mut style_selectors);
Expand Down Expand Up @@ -657,6 +666,7 @@ mod cosmetic_cache_tests {
"cosmetic.net##+js(nowebrtc.js)",
"g.cosmetic.net##+js(window.open-defuser.js)",
"c.g.cosmetic.net#@#+js(nowebrtc.js)",
"d.g.cosmetic.net#@#+js()",
]);
let resources = ResourceStorage::from_resources([
Resource {
Expand Down Expand Up @@ -698,6 +708,10 @@ mod cosmetic_cache_tests {
let out = cfcache.hostname_cosmetic_resources(&resources, "c.g.cosmetic.net", false);
expected.injected_script = "try {\nwindow.open-defuser.js\n} catch ( e ) { }\n".to_owned();
assert_eq!(out, expected);

let out = cfcache.hostname_cosmetic_resources(&resources, "d.g.cosmetic.net", false);
expected.injected_script = "".to_owned();
assert_eq!(out, expected);
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions third_party/rust/adblock/v0_8/crate/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ impl Engine {
/// `hidden_class_id_selectors` to obtain any stylesheets consisting of generic rules (if the
/// returned `generichide` value is false).
pub fn url_cosmetic_resources(&self, url: &str) -> UrlSpecificResources {
let request = Request::new(url, url, "document");
if request.is_err() {
let request = if let Ok(request) = Request::new(url, url, "document") {
request
} else {
return UrlSpecificResources::empty();
}
let request = request.unwrap();
};

let generichide = self.blocker.check_generic_hide(&request);
self.cosmetic_cache.hostname_cosmetic_resources(&self.resources, &request.hostname, generichide)
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/third_party.toml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ if (is_mac) {
'''

[dependencies.adblock]
version = "0.8.1"
version = "0.8.2"
default-features = false
features = ["full-regex-handling", "regex-debug-info", "css-validation"]
gn-variables-lib = '''
Expand Down

0 comments on commit 8e4c4ca

Please sign in to comment.