Skip to content

Commit faeedea

Browse files
committed
1 parent 3b67516 commit faeedea

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

src/js/static-net-filtering.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ var typeNameToTypeValue = {
7272
'inline-script': 15 << 4,
7373
'data': 16 << 4, // special: a generic data holder
7474
'redirect': 17 << 4,
75-
'webrtc': 18 << 4
75+
'webrtc': 18 << 4,
76+
'unsupported': 19 << 4
7677
};
7778
var otherTypeBitValue = typeNameToTypeValue.other;
7879

@@ -94,15 +95,10 @@ var typeValueToTypeName = {
9495
15: 'inline-script',
9596
16: 'data',
9697
17: 'redirect',
97-
18: 'webrtc'
98+
18: 'webrtc',
99+
19: 'unsupported'
98100
};
99101

100-
// All network request types to bitmap
101-
// bring origin to 0 (from 4 -- see typeNameToTypeValue)
102-
// left-shift 1 by the above-calculated value
103-
// subtract 1 to set all type bits
104-
var allNetRequestTypesBitmap = (1 << (otherTypeBitValue >>> 4)) - 1;
105-
106102
var BlockAnyTypeAnyParty = BlockAction | AnyType | AnyParty;
107103
var BlockAnyType = BlockAction | AnyType;
108104
var BlockAnyParty = BlockAction | AnyParty;
@@ -1330,6 +1326,12 @@ var FilterParser = function() {
13301326
this.reBadCSP = /(?:^|;)\s*report-(?:to|uri)\b/;
13311327
this.domainOpt = '';
13321328
this.noTokenHash = µb.urlTokenizer.tokenHashFromString('*');
1329+
this.unsupportedTypeBit = this.bitFromType('unsupported');
1330+
// All network request types to bitmap
1331+
// bring origin to 0 (from 4 -- see typeNameToTypeValue)
1332+
// left-shift 1 by the above-calculated value
1333+
// subtract 1 to set all type bits
1334+
this.allNetRequestTypeBits = (1 << (otherTypeBitValue >>> 4)) - 1;
13331335
this.reset();
13341336
};
13351337

@@ -1344,6 +1346,7 @@ FilterParser.prototype.toNormalizedType = {
13441346
'document': 'main_frame',
13451347
'elemhide': 'generichide',
13461348
'font': 'font',
1349+
'genericblock' : 'unsupported',
13471350
'generichide': 'generichide',
13481351
'image': 'image',
13491352
'inline-script': 'inline-script',
@@ -1358,7 +1361,7 @@ FilterParser.prototype.toNormalizedType = {
13581361
'stylesheet': 'stylesheet',
13591362
'subdocument': 'sub_frame',
13601363
'xmlhttprequest': 'xmlhttprequest',
1361-
'webrtc': 'webrtc',
1364+
'webrtc': 'unsupported',
13621365
'websocket': 'websocket'
13631366
};
13641367

@@ -1410,16 +1413,16 @@ FilterParser.prototype.parseTypeOption = function(raw, not) {
14101413
}
14111414

14121415
// Non-discrete network types can't be negated.
1413-
if ( (typeBit & allNetRequestTypesBitmap) === 0 ) {
1416+
if ( (typeBit & this.allNetRequestTypeBits) === 0 ) {
14141417
return;
14151418
}
14161419

14171420
// Negated type: set all valid network request type bits to 1
14181421
if (
1419-
(typeBit & allNetRequestTypesBitmap) !== 0 &&
1420-
(this.types & allNetRequestTypesBitmap) === 0
1422+
(typeBit & this.allNetRequestTypeBits) !== 0 &&
1423+
(this.types & this.allNetRequestTypeBits) === 0
14211424
) {
1422-
this.types |= allNetRequestTypesBitmap;
1425+
this.types |= this.allNetRequestTypeBits;
14231426
}
14241427
this.types &= ~typeBit;
14251428
};
@@ -1685,12 +1688,22 @@ FilterParser.prototype.parse = function(raw) {
16851688
pos = s.lastIndexOf('$');
16861689
if ( pos !== -1 ) {
16871690
// https://github.com/gorhill/uBlock/issues/952
1688-
// Discard Adguard-specific `$$` filters.
1691+
// Discard Adguard-specific `$$` filters.
16891692
if ( s.indexOf('$$') !== -1 ) {
16901693
this.unsupported = true;
16911694
return this;
16921695
}
16931696
this.parseOptions(s.slice(pos + 1));
1697+
// https://github.com/gorhill/uBlock/issues/2283
1698+
// Abort if type is only for unsupported types, otherwise
1699+
// toggle off `unsupported` bit.
1700+
if ( this.types & this.unsupportedTypeBit ) {
1701+
this.types &= ~(this.unsupportedTypeBit | this.allNetRequestTypeBits);
1702+
if ( this.types === 0 ) {
1703+
this.unsupported = true;
1704+
return this;
1705+
}
1706+
}
16941707
s = s.slice(0, pos);
16951708
}
16961709
}

0 commit comments

Comments
 (0)