Skip to content

Commit

Permalink
Allow filters without specific resource type to match any cpt
Browse files Browse the repository at this point in the history
  • Loading branch information
remusao committed Oct 7, 2018
1 parent dda08f2 commit 6584bcc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
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 6584bcc

Please sign in to comment.