From fd31cd3eb7497ac9abd22cbd0caef2a4d5447c84 Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Mon, 11 Sep 2023 12:51:56 -0700 Subject: [PATCH] update adblock-rust to v0.8.1 --- .../brave_shields/adblock/rs/Cargo.toml | 2 +- third_party/rust/Cargo.lock | 2 +- third_party/rust/adblock/v0_8/README.chromium | 4 +-- .../adblock/v0_8/crate/.cargo_vcs_info.json | 2 +- .../rust/adblock/v0_8/crate/Cargo.lock | 2 +- .../rust/adblock/v0_8/crate/Cargo.toml | 2 +- .../rust/adblock/v0_8/crate/Cargo.toml.orig | 2 +- .../rust/adblock/v0_8/crate/src/blocker.rs | 30 ++++++++++++++----- .../crate/src/resources/resource_storage.rs | 26 +++++++++++++++- third_party/rust/third_party.toml | 2 +- 10 files changed, 57 insertions(+), 17 deletions(-) diff --git a/components/brave_shields/adblock/rs/Cargo.toml b/components/brave_shields/adblock/rs/Cargo.toml index b7a43ece53bb..9cd6791233ec 100644 --- a/components/brave_shields/adblock/rs/Cargo.toml +++ b/components/brave_shields/adblock/rs/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -adblock = { version = "0.8.0", default-features = false, features = ["full-regex-handling", "regex-debug-info", "css-validation"] } +adblock = { version = "0.8.1", default-features = false, features = ["full-regex-handling", "regex-debug-info", "css-validation"] } cxx = "1.0" serde_json = "1.0" thiserror = "1.0" diff --git a/third_party/rust/Cargo.lock b/third_party/rust/Cargo.lock index 10f1a864bb3f..8fe756318048 100644 --- a/third_party/rust/Cargo.lock +++ b/third_party/rust/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "adblock" -version = "0.8.0" +version = "0.8.1" dependencies = [ "base64", "bitflags", diff --git a/third_party/rust/adblock/v0_8/README.chromium b/third_party/rust/adblock/v0_8/README.chromium index 73e30e2160aa..0eca9fb5306d 100644 --- a/third_party/rust/adblock/v0_8/README.chromium +++ b/third_party/rust/adblock/v0_8/README.chromium @@ -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.0 +Version: 0.8.1 Security Critical: no License: Mozilla Public License 2.0 -Revision: cb0dd04c193cf301403d7596bee326f4a0a1658b +Revision: bc39fa8a52bc96db18e8c14de73ed63d883a7b09 diff --git a/third_party/rust/adblock/v0_8/crate/.cargo_vcs_info.json b/third_party/rust/adblock/v0_8/crate/.cargo_vcs_info.json index caa9f4aa8557..021833609e52 100644 --- a/third_party/rust/adblock/v0_8/crate/.cargo_vcs_info.json +++ b/third_party/rust/adblock/v0_8/crate/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "cb0dd04c193cf301403d7596bee326f4a0a1658b" + "sha1": "bc39fa8a52bc96db18e8c14de73ed63d883a7b09" }, "path_in_vcs": "" } \ No newline at end of file diff --git a/third_party/rust/adblock/v0_8/crate/Cargo.lock b/third_party/rust/adblock/v0_8/crate/Cargo.lock index 67000c8cb25f..ae63b8c94c87 100644 --- a/third_party/rust/adblock/v0_8/crate/Cargo.lock +++ b/third_party/rust/adblock/v0_8/crate/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "adblock" -version = "0.8.0" +version = "0.8.1" dependencies = [ "addr", "base64", diff --git a/third_party/rust/adblock/v0_8/crate/Cargo.toml b/third_party/rust/adblock/v0_8/crate/Cargo.toml index 8a94a144446a..b51e864eeed3 100644 --- a/third_party/rust/adblock/v0_8/crate/Cargo.toml +++ b/third_party/rust/adblock/v0_8/crate/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2021" name = "adblock" -version = "0.8.0" +version = "0.8.1" authors = [ "Andrius Aucinas ", "Anton Lazarev ", diff --git a/third_party/rust/adblock/v0_8/crate/Cargo.toml.orig b/third_party/rust/adblock/v0_8/crate/Cargo.toml.orig index d2edd45e4307..f2432f9892c3 100644 --- a/third_party/rust/adblock/v0_8/crate/Cargo.toml.orig +++ b/third_party/rust/adblock/v0_8/crate/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "adblock" -version = "0.8.0" +version = "0.8.1" authors = ["Andrius Aucinas ", "Anton Lazarev "] edition = "2021" diff --git a/third_party/rust/adblock/v0_8/crate/src/blocker.rs b/third_party/rust/adblock/v0_8/crate/src/blocker.rs index 338eeacb2235..e69c058310dd 100644 --- a/third_party/rust/adblock/v0_8/crate/src/blocker.rs +++ b/third_party/rust/adblock/v0_8/crate/src/blocker.rs @@ -51,15 +51,18 @@ pub struct BlockerResult { /// modified at all, the new version will be here. This should be used /// as long as the request is not blocked. pub rewritten_url: Option, - /// Exception is `Some` when the blocker matched on an exception rule. + /// Contains a string representation of any matched exception rule. /// Effectively this means that there was a match, but the request should - /// not be blocked. It is a non-empty string if the blocker was initialized - /// from a list of rules with debugging enabled, otherwise the original - /// string representation is discarded to reduce memory use. + /// not be blocked. + /// + /// If debugging was _not_ enabled (see [`crate::FilterSet::new`]), this + /// will only contain a constant `"NetworkFilter"` placeholder string. pub exception: Option, - /// Filter--similarly to exception--includes the string representation of - /// the rule when there is a match and debugging is enabled. Otherwise, on - /// a match, it is `Some`. + /// When `matched` is true, this contains a string representation of the + /// matched blocking rule. + /// + /// If debugging was _not_ enabled (see [`crate::FilterSet::new`]), this + /// will only contain a constant `"NetworkFilter"` placeholder string. pub filter: Option, } @@ -2119,6 +2122,19 @@ fn test_removeparam_same_tokens() { } } +#[cfg(test)] +mod placeholder_string_tests { + /// If this changes, be sure to update the documentation for [`BlockerResult`] as well. + #[test] + fn test_constant_placeholder_string() { + let mut filter_set = crate::lists::FilterSet::new(false); + filter_set.add_filter("||example.com^", Default::default()).unwrap(); + let engine = crate::Engine::from_filter_set(filter_set, true); + let block = engine.check_network_request(&crate::request::Request::new("https://example.com", "https://example.com", "document").unwrap()); + assert_eq!(block.filter, Some("NetworkFilter".to_string())); + } +} + #[cfg(test)] mod legacy_rule_parsing_tests { use crate::test_utils::rules_from_lists; diff --git a/third_party/rust/adblock/v0_8/crate/src/resources/resource_storage.rs b/third_party/rust/adblock/v0_8/crate/src/resources/resource_storage.rs index 128a13e14a11..4d2f9f515b18 100644 --- a/third_party/rust/adblock/v0_8/crate/src/resources/resource_storage.rs +++ b/third_party/rust/adblock/v0_8/crate/src/resources/resource_storage.rs @@ -215,7 +215,7 @@ fn template_argument_regex(i: usize) -> Regex { fn patch_template_scriptlet(mut template: String, args: &[impl AsRef]) -> String { // `regex` treats `$` as a special character. Instead, `$$` is interpreted as a literal `$` // character. - args.iter().enumerate().for_each(|(i, arg)| { + args.iter().take(TEMPLATE_ARGUMENT_RE.len()).enumerate().for_each(|(i, arg)| { template = TEMPLATE_ARGUMENT_RE[i] .replace(&template, arg.as_ref().replace('$', "$$")) .to_string(); @@ -559,6 +559,30 @@ mod scriptlet_storage_tests { ); } + /// Currently, only 9 template arguments are supported - but reaching that limit should not + /// cause a panic. + #[test] + fn patch_argslist_many_args() { + let resources = ResourceStorage::from_resources([ + Resource { + name: "abort-current-script.js".into(), + aliases: vec!["acs.js".into()], + kind: ResourceType::Mime(MimeType::ApplicationJavascript), + content: base64::encode("{{1}} {{2}} {{3}} {{4}} {{5}} {{6}} {{7}} {{8}} {{9}} {{10}} {{11}} {{12}}"), + dependencies: vec![], + permission: Default::default(), + }, + ]); + + let args = parse_scriptlet_args("acs, this, probably, is, going, to, break, brave, and, crash, it, instead, of, ignoring, it"); + assert_eq!(args, vec!["acs", "this", "probably", "is", "going", "to", "break", "brave", "and", "crash", "it", "instead", "of", "ignoring", "it"]); + + assert_eq!( + resources.get_scriptlet_resource("acs, this, probably, is, going, to, break, brave, and, crash, it, instead, of, ignoring, it", Default::default()), + Ok("this probably is going to break brave and crash {{10}} {{11}} {{12}}".to_string()), + ); + } + #[test] fn permissions() { const PERM0: PermissionMask = PermissionMask::from_bits(0b00000001); diff --git a/third_party/rust/third_party.toml b/third_party/rust/third_party.toml index 08a1802603ff..0d698c7beee0 100644 --- a/third_party/rust/third_party.toml +++ b/third_party/rust/third_party.toml @@ -228,7 +228,7 @@ if (is_mac) { ''' [dependencies.adblock] -version = "0.8.0" +version = "0.8.1" default-features = false features = ["full-regex-handling", "regex-debug-info", "css-validation"] gn-variables-lib = '''