Initial import (#2266634)

epel10
Fabio Valentini 11 months ago
parent 7708064e66
commit 3742998a00
No known key found for this signature in database
GPG Key ID: 5AC5F572E5D410AF

1
.gitignore vendored

@ -0,0 +1 @@
/adblock-0.8.8.crate

@ -0,0 +1,245 @@
From f7342120f0a7c2e4955fc4601794f31f46da8140 Mon Sep 17 00:00:00 2001
From: Fabio Valentini <decathorpe@gmail.com>
Date: Wed, 28 Feb 2024 16:55:26 +0100
Subject: [PATCH] drop tests that require unshipped support code
---
src/blocker.rs | 172 -----------------------------------------
src/filters/network.rs | 28 -------
src/lib.rs | 4 -
3 files changed, 204 deletions(-)
diff --git a/src/blocker.rs b/src/blocker.rs
index 78d7edd..cc1435f 100644
--- a/src/blocker.rs
+++ b/src/blocker.rs
@@ -2135,175 +2135,3 @@ mod placeholder_string_tests {
assert_eq!(block.filter, Some("NetworkFilter".to_string()));
}
}
-
-#[cfg(test)]
-mod legacy_rule_parsing_tests {
- use crate::test_utils::rules_from_lists;
- use crate::lists::{parse_filters, FilterFormat, ParseOptions};
- use crate::blocker::{Blocker, BlockerOptions};
- use crate::blocker::vec_hashmap_len;
-
- struct ListCounts {
- pub filters: usize,
- pub cosmetic_filters: usize,
- pub exceptions: usize,
- pub duplicates: usize,
- }
-
- impl std::ops::Add<ListCounts> for ListCounts {
- type Output = ListCounts;
-
- fn add(self, other: ListCounts) -> Self::Output {
- ListCounts {
- filters: self.filters + other.filters,
- cosmetic_filters: self.cosmetic_filters + other.cosmetic_filters,
- exceptions: self.exceptions + other.exceptions,
- duplicates: 0, // Don't bother trying to calculate - lists could have cross-duplicated entries
- }
- }
- }
-
- // number of expected EasyList cosmetic rules from old engine is 31144, but is incorrect as it skips a few particularly long rules that are nevertheless valid
- // easyList = { 24478, 31144, 0, 5589 };
- // not handling (and not including) filters with the following options:
- // - $popup
- // - $elemhide
- // difference from original counts caused by not handling document/subdocument options and possibly miscounting on the blocker side.
- // Printing all non-cosmetic, non-html, non-comment/-empty rules and ones with no unsupported options yields 29142 items
- // This engine also handles 3 rules that old one does not
- const EASY_LIST: ListCounts = ListCounts { filters: 24064, cosmetic_filters: 31163, exceptions: 5796, duplicates: 0 };
- // easyPrivacy = { 11817, 0, 0, 1020 };
- // differences in counts explained by hashset size underreporting as detailed in the next two cases
- const EASY_PRIVACY: ListCounts = ListCounts { filters: 11889, cosmetic_filters: 0, exceptions: 1021, duplicates: 2 };
- // ublockUnbreak = { 4, 8, 0, 94 };
- // differences in counts explained by client.hostAnchoredExceptionHashSet->GetSize() underreporting when compared to client.numHostAnchoredExceptionFilters
- const UBLOCK_UNBREAK: ListCounts = ListCounts { filters: 4, cosmetic_filters: 8, exceptions: 98, duplicates: 0 };
- // braveUnbreak = { 31, 0, 0, 4 };
- // differences in counts explained by client.hostAnchoredHashSet->GetSize() underreporting when compared to client.numHostAnchoredFilters
- const BRAVE_UNBREAK: ListCounts = ListCounts { filters: 32, cosmetic_filters: 0, exceptions: 4, duplicates: 0 };
- // disconnectSimpleMalware = { 2450, 0, 0, 0 };
- const DISCONNECT_SIMPLE_MALWARE: ListCounts = ListCounts { filters: 2450, cosmetic_filters: 0, exceptions: 0, duplicates: 0 };
- // spam404MainBlacklist = { 5629, 166, 0, 0 };
- const SPAM_404_MAIN_BLACKLIST: ListCounts = ListCounts { filters: 5629, cosmetic_filters: 166, exceptions: 0, duplicates: 0 };
- const MALWARE_DOMAIN_LIST: ListCounts = ListCounts { filters: 1104, cosmetic_filters: 0, exceptions: 0, duplicates: 3 };
- const MALWARE_DOMAINS: ListCounts = ListCounts { filters: 26853, cosmetic_filters: 0, exceptions: 0, duplicates: 48 };
-
- fn check_list_counts(rule_lists: impl IntoIterator<Item=impl AsRef<str>>, format: FilterFormat, expectation: ListCounts) {
- let rules = rules_from_lists(rule_lists);
-
- let (network_filters, cosmetic_filters) = parse_filters(rules, true, ParseOptions { format, ..Default::default() });
-
- assert_eq!(
- (network_filters.len(),
- network_filters.iter().filter(|f| f.is_exception()).count(),
- cosmetic_filters.len()),
- (expectation.filters + expectation.exceptions,
- expectation.exceptions,
- expectation.cosmetic_filters),
- "Number of collected filters does not match expectation");
-
- let blocker_options = BlockerOptions {
- enable_optimizations: false, // optimizations will reduce number of rules
- };
-
- let blocker = Blocker::new(network_filters, &blocker_options);
-
- // Some filters in the filter_map are pointed at by multiple tokens, increasing the total number of items
- assert!(vec_hashmap_len(&blocker.exceptions.filter_map) + vec_hashmap_len(&blocker.generic_hide.filter_map)
- >= expectation.exceptions, "Number of collected exceptions does not match expectation");
-
- assert!(vec_hashmap_len(&blocker.filters.filter_map) +
- vec_hashmap_len(&blocker.importants.filter_map) +
- vec_hashmap_len(&blocker.redirects.filter_map) +
- vec_hashmap_len(&blocker.redirects.filter_map) +
- vec_hashmap_len(&blocker.csp.filter_map) >=
- expectation.filters - expectation.duplicates, "Number of collected network filters does not match expectation");
- }
-
- #[test]
- fn parse_easylist() {
- check_list_counts(["./data/test/easylist.txt"], FilterFormat::Standard, EASY_LIST);
- }
-
- #[test]
- fn parse_easyprivacy() {
- check_list_counts(["./data/test/easyprivacy.txt"], FilterFormat::Standard, EASY_PRIVACY);
- }
-
- #[test]
- fn parse_ublock_unbreak() {
- check_list_counts(["./data/test/ublock-unbreak.txt"], FilterFormat::Standard, UBLOCK_UNBREAK);
- }
-
- #[test]
- fn parse_brave_unbreak() {
- check_list_counts(["./data/test/brave-unbreak.txt"], FilterFormat::Standard, BRAVE_UNBREAK);
- }
-
- #[test]
- fn parse_brave_disconnect_simple_malware() {
- check_list_counts(["./data/test/disconnect-simple-malware.txt"], FilterFormat::Standard, DISCONNECT_SIMPLE_MALWARE);
- }
-
- #[test]
- fn parse_spam404_main_blacklist() {
- check_list_counts(["./data/test/spam404-main-blacklist.txt"], FilterFormat::Standard, SPAM_404_MAIN_BLACKLIST);
- }
-
- #[test]
- fn parse_malware_domain_list() {
- check_list_counts(["./data/test/malwaredomainlist.txt"], FilterFormat::Hosts, MALWARE_DOMAIN_LIST);
- }
-
- #[test]
- fn parse_malware_domain_list_just_hosts() {
- check_list_counts(["./data/test/malwaredomainlist_justhosts.txt"], FilterFormat::Hosts, MALWARE_DOMAIN_LIST);
- }
-
- #[test]
- fn parse_malware_domains() {
- check_list_counts(["./data/test/malwaredomains.txt"], FilterFormat::Hosts, MALWARE_DOMAINS);
- }
-
- #[test]
- fn parse_multilist() {
- let expectation = EASY_LIST + EASY_PRIVACY + UBLOCK_UNBREAK + BRAVE_UNBREAK;
- check_list_counts(
- [
- "./data/test/easylist.txt",
- "./data/test/easyprivacy.txt",
- "./data/test/ublock-unbreak.txt",
- "./data/test/brave-unbreak.txt",
- ],
- FilterFormat::Standard,
- expectation,
- )
- }
-
- #[test]
- fn parse_malware_multilist() {
- let expectation = SPAM_404_MAIN_BLACKLIST + DISCONNECT_SIMPLE_MALWARE;
- check_list_counts(
- [
- "./data/test/spam404-main-blacklist.txt",
- "./data/test/disconnect-simple-malware.txt",
- ],
- FilterFormat::Standard,
- expectation,
- )
- }
-
- #[test]
- fn parse_hosts_formats() {
- let mut expectation = MALWARE_DOMAIN_LIST + MALWARE_DOMAINS;
- expectation.duplicates = 69;
- check_list_counts(
- [
- "./data/test/malwaredomainlist.txt",
- "./data/test/malwaredomains.txt",
- ],
- FilterFormat::Hosts,
- expectation,
- )
- }
-}
diff --git a/src/filters/network.rs b/src/filters/network.rs
index 093b0e6..69f10d0 100644
--- a/src/filters/network.rs
+++ b/src/filters/network.rs
@@ -3386,31 +3386,3 @@ mod match_tests {
assert_eq!(get_url_after_hostname("https://www.youtube.com/?aclksa=l&ai=DChcSEwioqMfq5", "google.com"), "");
}
}
-
-#[cfg(test)]
-mod hash_collision_tests {
- use super::*;
-
- use crate::test_utils;
- use crate::lists::parse_filters;
- use std::collections::HashMap;
-
- #[test]
- fn check_rule_ids_no_collisions() {
- let rules = test_utils::rules_from_lists([
- "data/easylist.to/easylist/easylist.txt",
- "data/easylist.to/easylist/easyprivacy.txt",
- ]);
- let (network_filters, _) = parse_filters(rules, true, Default::default());
-
- let mut filter_ids: HashMap<Hash, String> = HashMap::new();
-
- for filter in network_filters {
- let id = filter.get_id();
- let rule = *filter.raw_line.unwrap_or_default();
- let existing_rule = filter_ids.get(&id);
- assert!(existing_rule.is_none() || existing_rule.unwrap() == &rule, "ID {} for {} already present from {}", id, rule, existing_rule.unwrap());
- filter_ids.insert(id, rule);
- }
- }
-}
diff --git a/src/lib.rs b/src/lib.rs
index 956f082..5db786a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -37,10 +37,6 @@ pub use engine::Engine;
#[doc(inline)]
pub use lists::FilterSet;
-#[cfg(test)]
-#[path = "../tests/test_utils.rs"]
-mod test_utils;
-
#[cfg(test)]
mod sync_tests {
#[allow(unused)]
--
2.44.0

@ -1,3 +0,0 @@
# rust-adblock
The rust-adblock package

@ -0,0 +1,86 @@
--- adblock-0.8.8/Cargo.toml 1970-01-01T00:00:01+00:00
+++ adblock-0.8.8/Cargo.toml 2024-02-28T16:16:52.749240+00:00
@@ -37,26 +37,6 @@
[lib]
bench = false
-[[bench]]
-name = "bench_regex"
-harness = false
-
-[[bench]]
-name = "bench_matching"
-harness = false
-
-[[bench]]
-name = "bench_url"
-harness = false
-
-[[bench]]
-name = "bench_rules"
-harness = false
-
-[[bench]]
-name = "bench_redirect_performance"
-harness = false
-
[dependencies.addr]
version = "0.14"
features = ["psl"]
@@ -68,10 +48,6 @@
[dependencies.bitflags]
version = "1.2"
-
-[dependencies.cssparser]
-version = "0.28"
-optional = true
[dependencies.idna]
version = "0.2"
@@ -96,14 +72,10 @@
version = "1.5"
[dependencies.rmp-serde]
-version = "0.15"
+version = "1"
[dependencies.seahash]
version = "3"
-
-[dependencies.selectors]
-version = "0.23"
-optional = true
[dependencies.serde]
version = "1.0"
@@ -122,9 +94,6 @@
[dependencies.url]
version = "2.2"
-[dev-dependencies.criterion]
-version = "0.4"
-
[dev-dependencies.csv]
version = "1"
@@ -132,7 +101,7 @@
version = "0.3"
[dev-dependencies.mock_instant]
-version = "0.2"
+version = "0.3"
features = ["sync"]
[dev-dependencies.reqwest]
@@ -152,10 +121,6 @@
[features]
content-blocking = ["serde_json"]
-css-validation = [
- "cssparser",
- "selectors",
-]
default = [
"embedded-domain-resolver",
"full-regex-handling",

@ -0,0 +1,197 @@
# Generated by rust2rpm 26
%bcond_without check
%global debug_package %{nil}
%global crate adblock
Name: rust-adblock
Version: 0.8.8
Release: %autorelease
Summary: Native Rust module for Adblock Plus syntax
License: MPL-2.0
URL: https://crates.io/crates/adblock
Source: %{crates_source}
# Manually created patch for downstream crate metadata changes
# * bump rmp-serde dependency from 0.15 to 1
# * bump mock_instant dev-dependency from 0.2 to 0.3
# * drop unused, benchmark-only criterion dev-dependency
# * drop unused css-validation feature with outdated dependencies
Patch: adblock-fix-metadata.diff
# * drop tests that require unshipped support code
Patch: 0001-drop-tests-that-require-unshipped-support-code.patch
BuildRequires: cargo-rpm-macros >= 24
%global _description %{expand:
Native Rust module for Adblock Plus syntax (e.g. EasyList, EasyPrivacy)
filter parsing and matching.}
%description %{_description}
%package devel
Summary: %{summary}
BuildArch: noarch
%description devel %{_description}
This package contains library source intended for building other packages which
use the "%{crate}" crate.
%files devel
%license %{crate_instdir}/LICENSE
%doc %{crate_instdir}/README.md
%{crate_instdir}/
%package -n %{name}+default-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+default-devel %{_description}
This package contains library source intended for building other packages which
use the "default" feature of the "%{crate}" crate.
%files -n %{name}+default-devel
%ghost %{crate_instdir}/Cargo.toml
%package -n %{name}+addr-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+addr-devel %{_description}
This package contains library source intended for building other packages which
use the "addr" feature of the "%{crate}" crate.
%files -n %{name}+addr-devel
%ghost %{crate_instdir}/Cargo.toml
%package -n %{name}+content-blocking-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+content-blocking-devel %{_description}
This package contains library source intended for building other packages which
use the "content-blocking" feature of the "%{crate}" crate.
%files -n %{name}+content-blocking-devel
%ghost %{crate_instdir}/Cargo.toml
%package -n %{name}+embedded-domain-resolver-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+embedded-domain-resolver-devel %{_description}
This package contains library source intended for building other packages which
use the "embedded-domain-resolver" feature of the "%{crate}" crate.
%files -n %{name}+embedded-domain-resolver-devel
%ghost %{crate_instdir}/Cargo.toml
%package -n %{name}+full-regex-handling-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+full-regex-handling-devel %{_description}
This package contains library source intended for building other packages which
use the "full-regex-handling" feature of the "%{crate}" crate.
%files -n %{name}+full-regex-handling-devel
%ghost %{crate_instdir}/Cargo.toml
%package -n %{name}+lifeguard-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+lifeguard-devel %{_description}
This package contains library source intended for building other packages which
use the "lifeguard" feature of the "%{crate}" crate.
%files -n %{name}+lifeguard-devel
%ghost %{crate_instdir}/Cargo.toml
%package -n %{name}+object-pooling-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+object-pooling-devel %{_description}
This package contains library source intended for building other packages which
use the "object-pooling" feature of the "%{crate}" crate.
%files -n %{name}+object-pooling-devel
%ghost %{crate_instdir}/Cargo.toml
%package -n %{name}+regex-debug-info-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+regex-debug-info-devel %{_description}
This package contains library source intended for building other packages which
use the "regex-debug-info" feature of the "%{crate}" crate.
%files -n %{name}+regex-debug-info-devel
%ghost %{crate_instdir}/Cargo.toml
%package -n %{name}+resource-assembler-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+resource-assembler-devel %{_description}
This package contains library source intended for building other packages which
use the "resource-assembler" feature of the "%{crate}" crate.
%files -n %{name}+resource-assembler-devel
%ghost %{crate_instdir}/Cargo.toml
%package -n %{name}+serde_json-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+serde_json-devel %{_description}
This package contains library source intended for building other packages which
use the "serde_json" feature of the "%{crate}" crate.
%files -n %{name}+serde_json-devel
%ghost %{crate_instdir}/Cargo.toml
%package -n %{name}+unsync-regex-caching-devel
Summary: %{summary}
BuildArch: noarch
%description -n %{name}+unsync-regex-caching-devel %{_description}
This package contains library source intended for building other packages which
use the "unsync-regex-caching" feature of the "%{crate}" crate.
%files -n %{name}+unsync-regex-caching-devel
%ghost %{crate_instdir}/Cargo.toml
%prep
%autosetup -n %{crate}-%{version} -p1
%cargo_prep
%generate_buildrequires
%cargo_generate_buildrequires
%build
%cargo_build
%install
%cargo_install
%if %{with check}
%check
%cargo_test
%endif
%changelog
%autochangelog

@ -0,0 +1 @@
SHA512 (adblock-0.8.8.crate) = 7c6682cc18330440bd80505fe3a6f322ad2c10c9bbfa7d26fade7502dda464d6cd6871f18c9817011108bb624ce4b6615d9a2fa479fe7d353d6b1b06c5d20a76
Loading…
Cancel
Save