@@ -1293,6 +1293,7 @@ FilterBucket.fromSelfie = function() {
12931293/******************************************************************************/
12941294
12951295var FilterParser = function ( ) {
1296+ this . cantWebsocket = vAPI . cantWebsocket ;
12961297 this . reHostnameRule1 = / ^ [ 0 - 9 a - z ] [ 0 - 9 a - z . - ] * [ 0 - 9 a - z ] $ / i;
12971298 this . reHostnameRule2 = / ^ \* * [ 0 - 9 a - z ] [ 0 - 9 a - z . - ] * [ 0 - 9 a - z ] \^ ? $ / i;
12981299 this . reCleanupHostnameRule2 = / ^ \* * | \^ $ / g;
@@ -1302,6 +1303,7 @@ var FilterParser = function() {
13021303 this . reHasUppercase = / [ A - Z ] / ;
13031304 this . reIsolateHostname = / ^ ( \* ? \. ) ? ( [ ^ \x00 - \x24 \x26 - \x2C \x2F \x3A - \x5E \x60 \x7B - \x7F ] + ) ( .* ) / ;
13041305 this . reHasUnicode = / [ ^ \x00 - \x7F ] / ;
1306+ this . reWebsocketAny = / ^ w s s ? : (?: \/ \/ ) ? $ / ;
13051307 this . domainOpt = '' ;
13061308 this . reset ( ) ;
13071309} ;
@@ -1353,11 +1355,17 @@ FilterParser.prototype.reset = function() {
13531355
13541356/******************************************************************************/
13551357
1358+ FilterParser . prototype . bitFromType = function ( type ) {
1359+ return 1 << ( ( typeNameToTypeValue [ type ] >>> 4 ) - 1 ) ;
1360+ } ;
1361+
1362+ /******************************************************************************/
1363+
13561364// https://github.com/chrisaljoudi/uBlock/issues/589
13571365// Be ready to handle multiple negated types
13581366
13591367FilterParser . prototype . parseOptType = function ( raw , not ) {
1360- var typeBit = 1 << ( ( typeNameToTypeValue [ this . toNormalizedType [ raw ] ] >>> 4 ) - 1 ) ;
1368+ var typeBit = this . bitFromType ( this . toNormalizedType [ raw ] ) ;
13611369
13621370 if ( ! not ) {
13631371 this . types |= typeBit ;
@@ -1424,6 +1432,11 @@ FilterParser.prototype.parseOptions = function(s) {
14241432 }
14251433 if ( this . toNormalizedType . hasOwnProperty ( opt ) ) {
14261434 this . parseOptType ( opt , not ) ;
1435+ // Due to ABP categorizing `websocket` requests as `other`, we need
1436+ // to add `websocket` for when `other` is used.
1437+ if ( opt === 'other' ) {
1438+ this . parseOptType ( 'websocket' , not ) ;
1439+ }
14271440 continue ;
14281441 }
14291442 if ( opt . startsWith ( 'domain=' ) ) {
@@ -1601,6 +1614,20 @@ FilterParser.prototype.parse = function(raw) {
16011614
16021615 this . f = this . reHasUppercase . test ( s ) ? s . toLowerCase ( ) : s ;
16031616
1617+ // https://github.com/gorhill/uBlock/issues/1943#issuecomment-243188946
1618+ // Convert websocket-related filter where possible to a format which
1619+ // can be handled using CSP injection.
1620+ if (
1621+ this . cantWebsocket &&
1622+ this . anchor === - 1 &&
1623+ this . firstParty === false &&
1624+ this . thirdParty === false &&
1625+ this . reWebsocketAny . test ( this . f )
1626+ ) {
1627+ this . f = '*' ;
1628+ this . types = this . bitFromType ( 'websocket' ) ;
1629+ }
1630+
16041631 return this ;
16051632} ;
16061633
0 commit comments