From 363f3a512b5aa6925fcb50d566b3c400bc37c086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Berson?= Date: Sun, 7 Oct 2018 12:05:10 +0200 Subject: [PATCH] Allow filters without specific resource type to match any cpt --- CHANGELOG.md | 2 ++ package-lock.json | 30 ++++++++---------------------- src/parsing/network-filter.ts | 22 ++++++++++++---------- test/matching.test.ts | 1 - 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b286c1a87..0d7e1027e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## *not released* + * Allow filters without specific resource type to match any cpt [#42](https://github.com/cliqz-oss/adblocker/pull/42) + ## 0.2.0 *2018-09-25* diff --git a/package-lock.json b/package-lock.json index d5817c2310..f083549eae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@cliqz/adblocker", - "version": "0.1.13", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2521,14 +2521,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2543,20 +2541,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -2673,8 +2668,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -2686,7 +2680,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2701,7 +2694,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2709,14 +2701,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -2735,7 +2725,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -2816,8 +2805,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -2829,7 +2817,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -2951,7 +2938,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/src/parsing/network-filter.ts b/src/parsing/network-filter.ts index f236b9040d..dffb5ae6f3 100644 --- a/src/parsing/network-filter.ts +++ b/src/parsing/network-filter.ts @@ -177,13 +177,13 @@ export class NetworkFilter implements IFilter { hostname, id, }: { - mask: number, - filter: string, - optDomains: string, - optNotDomains: string, - redirect: string, - hostname: string, - id: number, + mask: number; + filter: string; + optDomains: string; + optNotDomains: string; + redirect: string; + hostname: string; + id: number; }) { // Those fields should not be mutated. this.id = id; @@ -410,8 +410,9 @@ export class NetworkFilter implements IFilter { return getBit(this.mask, mask); } - // If content type is not supported then we return false - return false; + // If content type is not supported (or not specified), we return `true` + // only if the filter does not specify any resource type. + return this.fromAny(); } public isFuzzy() { @@ -551,7 +552,8 @@ export function parseNetworkFilter(rawLine: string): NetworkFilter | null { const line: string = rawLine; // Represent options as a bitmask - let mask: number = NETWORK_FILTER_MASK.thirdParty | NETWORK_FILTER_MASK.firstParty; + let mask: number = + NETWORK_FILTER_MASK.thirdParty | NETWORK_FILTER_MASK.firstParty; // Temporary masks for positive (e.g.: $script) and negative (e.g.: $~script) // content type options. diff --git a/test/matching.test.ts b/test/matching.test.ts index ad2452451e..f9b34bff89 100644 --- a/test/matching.test.ts +++ b/test/matching.test.ts @@ -23,7 +23,6 @@ declare global { expect.extend({ toMatchRequest(filter, request) { const processedRequest = processRawRequest({ - cpt: 2, sourceUrl: '', url: '', ...request,