mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
Report specific filter before generic one
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2092
Regression from:
- 72bb89495b
This commit is contained in:
parent
3af9cd2b71
commit
83d028ac7d
3 changed files with 26 additions and 31 deletions
|
@ -118,7 +118,7 @@ const onMessage = function(request, sender, callback) {
|
|||
return;
|
||||
|
||||
case 'listsFromCosmeticFilter':
|
||||
staticFilteringReverseLookup.fromCosmeticFilter(
|
||||
staticFilteringReverseLookup.fromExtendedFilter(
|
||||
request
|
||||
).then(response => {
|
||||
callback(response);
|
||||
|
|
|
@ -23,31 +23,28 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
{
|
||||
// >>>>> start of local scope
|
||||
let listEntries = Object.create(null);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
const reBlockStart = /^#block-start-([\w:]+)\n/gm;
|
||||
let listEntries = Object.create(null);
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/2092
|
||||
// Order of ids matters
|
||||
|
||||
const extractBlocks = function(content, ...ids) {
|
||||
reBlockStart.lastIndex = 0;
|
||||
const out = [];
|
||||
let match = reBlockStart.exec(content);
|
||||
while ( match !== null ) {
|
||||
const beg = match.index + match[0].length;
|
||||
const id = match[1];
|
||||
if ( ids.includes(id) ) {
|
||||
const end = content.indexOf(`#block-end-${id}`, beg);
|
||||
out.push(content.slice(beg, end));
|
||||
reBlockStart.lastIndex = end;
|
||||
}
|
||||
match = reBlockStart.exec(content);
|
||||
for ( const id of ids ) {
|
||||
const pattern = `#block-start-${id}\n`;
|
||||
let beg = content.indexOf(pattern);
|
||||
if ( beg === -1 ) { continue; }
|
||||
beg += pattern.length;
|
||||
const end = content.indexOf(`#block-end-${id}`, beg);
|
||||
out.push(content.slice(beg, end));
|
||||
}
|
||||
return out.join('\n');
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// https://github.com/MajkiIT/polish-ads-filter/issues/14768#issuecomment-536006312
|
||||
// Avoid reporting badfilter-ed filters.
|
||||
|
||||
|
@ -66,8 +63,7 @@ const fromNetFilter = function(details) {
|
|||
// We need an exact match.
|
||||
// https://github.com/gorhill/uBlock/issues/1392
|
||||
// https://github.com/gorhill/uBlock/issues/835
|
||||
const notFound = pos !== 0 &&
|
||||
content.charCodeAt(pos - 1) !== 0x0A;
|
||||
const notFound = pos !== 0 && content.charCodeAt(pos - 1) !== 0x0A;
|
||||
pos += compiledFilter.length;
|
||||
if (
|
||||
notFound ||
|
||||
|
@ -90,6 +86,8 @@ const fromNetFilter = function(details) {
|
|||
self.postMessage({ id: details.id, response });
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Looking up filter lists from a cosmetic filter is a bit more complicated
|
||||
// than with network filters:
|
||||
//
|
||||
|
@ -110,7 +108,7 @@ const fromNetFilter = function(details) {
|
|||
// FilterContainer.fromCompiledContent() is our reference code to create
|
||||
// the various compiled versions.
|
||||
|
||||
const fromCosmeticFilter = function(details) {
|
||||
const fromExtendedFilter = function(details) {
|
||||
const match = /^#@?#\^?/.exec(details.rawFilter);
|
||||
const prefix = match[0];
|
||||
const exception = prefix.charAt(1) === '@';
|
||||
|
@ -161,8 +159,8 @@ const fromCosmeticFilter = function(details) {
|
|||
if ( entry === undefined ) { continue; }
|
||||
const content = extractBlocks(
|
||||
entry.content,
|
||||
'COSMETIC_FILTERS:GENERIC',
|
||||
'COSMETIC_FILTERS:SPECIFIC',
|
||||
'COSMETIC_FILTERS:GENERIC',
|
||||
'SCRIPTLET_FILTERS',
|
||||
'HTML_FILTERS',
|
||||
'HTTPHEADER_FILTERS'
|
||||
|
@ -270,7 +268,9 @@ const fromCosmeticFilter = function(details) {
|
|||
self.postMessage({ id: details.id, response });
|
||||
};
|
||||
|
||||
self.onmessage = function(e) { // jshint ignore:line
|
||||
/******************************************************************************/
|
||||
|
||||
self.onmessage = function(e) {
|
||||
const msg = e.data;
|
||||
|
||||
switch ( msg.what ) {
|
||||
|
@ -286,15 +286,10 @@ self.onmessage = function(e) { // jshint ignore:line
|
|||
fromNetFilter(msg);
|
||||
break;
|
||||
|
||||
case 'fromCosmeticFilter':
|
||||
fromCosmeticFilter(msg);
|
||||
case 'fromExtendedFilter':
|
||||
fromExtendedFilter(msg);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// <<<<< end of local scope
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -155,7 +155,7 @@ const fromNetFilter = async function(rawFilter) {
|
|||
});
|
||||
};
|
||||
|
||||
const fromCosmeticFilter = async function(details) {
|
||||
const fromExtendedFilter = async function(details) {
|
||||
if (
|
||||
typeof details.rawFilter !== 'string' ||
|
||||
details.rawFilter === ''
|
||||
|
@ -169,7 +169,7 @@ const fromCosmeticFilter = async function(details) {
|
|||
const hostname = hostnameFromURI(details.url);
|
||||
|
||||
worker.postMessage({
|
||||
what: 'fromCosmeticFilter',
|
||||
what: 'fromExtendedFilter',
|
||||
id: id,
|
||||
domain: domainFromHostname(hostname),
|
||||
hostname: hostname,
|
||||
|
@ -203,7 +203,7 @@ const resetLists = function() {
|
|||
|
||||
const staticFilteringReverseLookup = {
|
||||
fromNetFilter,
|
||||
fromCosmeticFilter,
|
||||
fromExtendedFilter,
|
||||
resetLists,
|
||||
shutdown: stopWorker
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue