Skip to content

Commit

Permalink
Allow filters without specific resource type to match any cpt (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
remusao authored Oct 8, 2018
1 parent dda08f2 commit a371c0c
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 37 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
2 changes: 1 addition & 1 deletion dist/adblocker.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/adblocker.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/adblocker.umd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/pattern-matching.es
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ var NetworkFilter = (function () {
if (mask !== undefined) {
return getBit(this.mask, mask);
}
return false;
return this.fromAny();
};
NetworkFilter.prototype.isFuzzy = function () {
return getBit(this.mask, 524288);
Expand Down
30 changes: 8 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions src/parsing/network-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion test/matching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ declare global {
expect.extend({
toMatchRequest(filter, request) {
const processedRequest = processRawRequest({
cpt: 2,
sourceUrl: '',
url: '',
...request,
Expand Down

0 comments on commit a371c0c

Please sign in to comment.