This commit is contained in:
Raymond Hill 2018-03-01 13:11:17 -05:00
parent 8b538de0cd
commit 959f68ce89
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 11 additions and 6 deletions

View File

@ -115,13 +115,13 @@ var fromNetFilter = function(details) {
var fromCosmeticFilter = function(details) { var fromCosmeticFilter = function(details) {
var match = /^#@?#\^?/.exec(details.rawFilter), var match = /^#@?#\^?/.exec(details.rawFilter),
prefix = match[0], prefix = match[0],
exception = prefix.charAt(1) === '@',
selector = details.rawFilter.slice(prefix.length); selector = details.rawFilter.slice(prefix.length);
// The longer the needle, the lower the number of false positives. // The longer the needle, the lower the number of false positives.
var needles = selector.match(/\w+/g).sort(function(a, b) { var needle = selector.match(/\w+/g).reduce(function(a, b) {
return b.length - a.length; return a.length > b.length ? a : b;
}); });
var reNeedle = new RegExp(needles[0], 'g');
var reHostname = new RegExp( var reHostname = new RegExp(
'^' + '^' +
@ -163,12 +163,14 @@ var fromCosmeticFilter = function(details) {
entry = listEntries[assetKey]; entry = listEntries[assetKey];
if ( entry === undefined ) { continue; } if ( entry === undefined ) { continue; }
content = extractBlocks(entry.content, 1000, 2000); content = extractBlocks(entry.content, 1000, 2000);
pos = 0;
found = undefined; found = undefined;
while ( (match = reNeedle.exec(content)) !== null ) { while ( (pos = content.indexOf(needle, pos)) !== -1 ) {
beg = content.lastIndexOf('\n', match.index); beg = content.lastIndexOf('\n', pos);
if ( beg === -1 ) { beg = 0; } if ( beg === -1 ) { beg = 0; }
end = content.indexOf('\n', reNeedle.lastIndex); end = content.indexOf('\n', pos);
if ( end === -1 ) { end = content.length; } if ( end === -1 ) { end = content.length; }
pos = end;
fargs = JSON.parse(content.slice(beg, end)); fargs = JSON.parse(content.slice(beg, end));
switch ( fargs[0] ) { switch ( fargs[0] ) {
case 0: // id-based case 0: // id-based
@ -215,6 +217,9 @@ var fromCosmeticFilter = function(details) {
case 32: case 32:
case 64: case 64:
case 65: case 65:
if ( exception !== (fargs[1].charAt(0) === '!') ) {
break;
}
isProcedural = fargs[3].charCodeAt(0) === 0x7B; isProcedural = fargs[3].charCodeAt(0) === 0x7B;
if ( if (
isProcedural === false && fargs[3] !== selector || isProcedural === false && fargs[3] !== selector ||