1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-02 09:09:38 +02:00
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

View File

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