Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to latest abp2dnr #11

Merged
merged 6 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@adguard/tsurlfilter": "^2.1.11",
"@ghostery/abp2dnr": "ghostery/abp2dnr#9e52b185e03d2d24170daaa5de0832e473d4b09f"
"@eyeo/webext-ad-filtering-solution": "^1.2.0"
},
"devDependencies": {
"@ghostery/trackerdb": "^1.0.36",
Expand Down
21 changes: 13 additions & 8 deletions src/converters/abp.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { convertFilter } from "@ghostery/abp2dnr";
import { Filter } from "adblockpluscore/lib/filterClasses";
import { FilterParsingError, normalize } from "@eyeo/webext-ad-filtering-solution/adblockpluscore/lib/filters/index.js";
import { createConverter } from "@eyeo/webext-ad-filtering-solution/adblockpluscore/lib/dnr/index.js";
import { normalizeFilter, normalizeRule } from "./helpers";

export default async function convert(filters) {
const converter = createConverter({ isRegexSupported: () => true });
const rules = [];
const errors = [];
let nextId = 1;
for (const filter of filters) {
try {
const normalizedFilter = normalizeFilter(Filter.normalize(filter));
const abpFilter = Filter.fromText(normalizedFilter);
const dnrRules = await convertFilter(abpFilter, () => ({
isSupported: true,
}));
const normalizedFilter = normalizeFilter(normalize(filter));
const dnrRules = converter(normalizedFilter);
if (dnrRules instanceof FilterParsingError) {
throw dnrRules;
}
if (dnrRules.length > 0) {
rules.push(...dnrRules);
for (const rule of dnrRules) {
rule.id = nextId++;
rules.push(rule);
}
} else {
throw new Error("Unknown problem");
}
Expand Down
5 changes: 3 additions & 2 deletions test/unit/converters/abp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ describe('abp converter', () => {
},
condition: {
domainType: "thirdParty",
initiatorDomains: [
seia-soto marked this conversation as resolved.
Show resolved Hide resolved
domains: [
"x.z"
],
isUrlFilterCaseSensitive: false,
urlFilter: "tinypass.com"
},
priority: 2000
priority: 2000,
id: 1
});
});

Expand Down
Loading