Skip to content

Commit

Permalink
update adblock-rust to v0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Sep 11, 2023
1 parent 4898585 commit fd31cd3
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 17 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.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"
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.0
Version: 0.8.1
Security Critical: no
License: Mozilla Public License 2.0
Revision: cb0dd04c193cf301403d7596bee326f4a0a1658b
Revision: bc39fa8a52bc96db18e8c14de73ed63d883a7b09
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": "cb0dd04c193cf301403d7596bee326f4a0a1658b"
"sha1": "bc39fa8a52bc96db18e8c14de73ed63d883a7b09"
},
"path_in_vcs": ""
}
2 changes: 1 addition & 1 deletion 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.0"
version = "0.8.1"
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.

30 changes: 23 additions & 7 deletions third_party/rust/adblock/v0_8/crate/src/blocker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// 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<String>,
/// 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<String>,
}

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ fn template_argument_regex(i: usize) -> Regex {
fn patch_template_scriptlet(mut template: String, args: &[impl AsRef<str>]) -> 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();
Expand Down Expand Up @@ -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);
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.0"
version = "0.8.1"
default-features = false
features = ["full-regex-handling", "regex-debug-info", "css-validation"]
gn-variables-lib = '''
Expand Down

0 comments on commit fd31cd3

Please sign in to comment.