mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-18 17:02:27 +02:00
Ignore !#include
directives within inactive !#if
/!#endif
blocks
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1113
This commit is contained in:
parent
ae57affea5
commit
aab3812089
@ -244,6 +244,7 @@ api.fetchFilterList = async function(mainlistURL) {
|
|||||||
|
|
||||||
const sublistURLs = new Set();
|
const sublistURLs = new Set();
|
||||||
|
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1113
|
||||||
const processIncludeDirectives = function(results) {
|
const processIncludeDirectives = function(results) {
|
||||||
const out = [];
|
const out = [];
|
||||||
const reInclude = /^!#include +(\S+)/gm;
|
const reInclude = /^!#include +(\S+)/gm;
|
||||||
@ -254,10 +255,17 @@ api.fetchFilterList = async function(mainlistURL) {
|
|||||||
}
|
}
|
||||||
if ( result instanceof Object === false ) { continue; }
|
if ( result instanceof Object === false ) { continue; }
|
||||||
const content = result.content;
|
const content = result.content;
|
||||||
|
const slices = µBlock.processDirectives.split(content);
|
||||||
|
for ( let i = 0, n = slices.length - 1; i < n; i++ ) {
|
||||||
|
const slice = content.slice(slices[i+0], slices[i+1]);
|
||||||
|
if ( (i & 1) !== 0 ) {
|
||||||
|
out.push(slice);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let lastIndex = 0;
|
let lastIndex = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ( rootDirectoryURL === undefined ) { break; }
|
if ( rootDirectoryURL === undefined ) { break; }
|
||||||
const match = reInclude.exec(content);
|
const match = reInclude.exec(slice);
|
||||||
if ( match === null ) { break; }
|
if ( match === null ) { break; }
|
||||||
if ( toParsedURL(match[1]) !== undefined ) { continue; }
|
if ( toParsedURL(match[1]) !== undefined ) { continue; }
|
||||||
if ( match[1].indexOf('..') !== -1 ) { continue; }
|
if ( match[1].indexOf('..') !== -1 ) { continue; }
|
||||||
@ -268,14 +276,15 @@ api.fetchFilterList = async function(mainlistURL) {
|
|||||||
if ( sublistURLs.has(subURL) ) { continue; }
|
if ( sublistURLs.has(subURL) ) { continue; }
|
||||||
sublistURLs.add(subURL);
|
sublistURLs.add(subURL);
|
||||||
out.push(
|
out.push(
|
||||||
content.slice(lastIndex, match.index),
|
slice.slice(lastIndex, match.index),
|
||||||
`! >>>>>>>> ${subURL}`,
|
`! >>>>>>>> ${subURL}`,
|
||||||
api.fetchText(subURL),
|
api.fetchText(subURL),
|
||||||
`! <<<<<<<< ${subURL}`
|
`! <<<<<<<< ${subURL}`
|
||||||
);
|
);
|
||||||
lastIndex = reInclude.lastIndex;
|
lastIndex = reInclude.lastIndex;
|
||||||
}
|
}
|
||||||
out.push(lastIndex === 0 ? content : content.slice(lastIndex));
|
out.push(lastIndex === 0 ? slice : slice.slice(lastIndex));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
@ -799,7 +799,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
// https://adblockplus.org/en/filters
|
// https://adblockplus.org/en/filters
|
||||||
const staticNetFilteringEngine = this.staticNetFilteringEngine;
|
const staticNetFilteringEngine = this.staticNetFilteringEngine;
|
||||||
const staticExtFilteringEngine = this.staticExtFilteringEngine;
|
const staticExtFilteringEngine = this.staticExtFilteringEngine;
|
||||||
const lineIter = new this.LineIterator(this.processDirectives(rawText));
|
const lineIter = new this.LineIterator(this.processDirectives.prune(rawText));
|
||||||
const parser = new vAPI.StaticFilteringParser();
|
const parser = new vAPI.StaticFilteringParser();
|
||||||
|
|
||||||
parser.setMaxTokenLength(this.urlTokenizer.MAX_TOKEN_LENGTH);
|
parser.setMaxTokenLength(this.urlTokenizer.MAX_TOKEN_LENGTH);
|
||||||
@ -854,14 +854,17 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
|
|
||||||
// https://github.com/AdguardTeam/AdguardBrowserExtension/issues/917
|
// https://github.com/AdguardTeam/AdguardBrowserExtension/issues/917
|
||||||
|
|
||||||
µBlock.processDirectives = function(content) {
|
µBlock.processDirectives = {
|
||||||
const reIf = /^!#(if|endif)\b([^\n]*)/gm;
|
// This method returns an array of indices, corresponding to position in
|
||||||
|
// the content string which should alternatively be parsed and discarded.
|
||||||
|
split: function(content) {
|
||||||
|
const reIf = /^!#(if|endif)\b([^\n]*)(?:[\n\r]+|$)/gm;
|
||||||
const stack = [];
|
const stack = [];
|
||||||
const shouldDiscard = ( ) => stack.some(v => v);
|
const shouldDiscard = ( ) => stack.some(v => v);
|
||||||
const parts = [];
|
const parts = [ 0 ];
|
||||||
let beg = 0, discard = false;
|
let discard = false;
|
||||||
|
|
||||||
while ( beg < content.length ) {
|
for (;;) {
|
||||||
const match = reIf.exec(content);
|
const match = reIf.exec(content);
|
||||||
if ( match === null ) { break; }
|
if ( match === null ) { break; }
|
||||||
|
|
||||||
@ -870,14 +873,14 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
let expr = match[2].trim();
|
let expr = match[2].trim();
|
||||||
const target = expr.charCodeAt(0) === 0x21 /* '!' */;
|
const target = expr.charCodeAt(0) === 0x21 /* '!' */;
|
||||||
if ( target ) { expr = expr.slice(1); }
|
if ( target ) { expr = expr.slice(1); }
|
||||||
const token = this.processDirectives.tokens.get(expr);
|
const token = this.tokens.get(expr);
|
||||||
const startDiscard =
|
const startDiscard =
|
||||||
token === 'false' &&
|
token === 'false' &&
|
||||||
target === false ||
|
target === false ||
|
||||||
token !== undefined &&
|
token !== undefined &&
|
||||||
vAPI.webextFlavor.soup.has(token) === target;
|
vAPI.webextFlavor.soup.has(token) === target;
|
||||||
if ( discard === false && startDiscard ) {
|
if ( discard === false && startDiscard ) {
|
||||||
parts.push(content.slice(beg, match.index));
|
parts.push(match.index);
|
||||||
discard = true;
|
discard = true;
|
||||||
}
|
}
|
||||||
stack.push(startDiscard);
|
stack.push(startDiscard);
|
||||||
@ -887,7 +890,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
stack.pop();
|
stack.pop();
|
||||||
const stopDiscard = shouldDiscard() === false;
|
const stopDiscard = shouldDiscard() === false;
|
||||||
if ( discard && stopDiscard ) {
|
if ( discard && stopDiscard ) {
|
||||||
beg = match.index + match[0].length + 1;
|
parts.push(match.index + match[0].length);
|
||||||
discard = false;
|
discard = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -897,14 +900,22 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( stack.length === 0 && parts.length !== 0 ) {
|
parts.push(content.length);
|
||||||
parts.push(content.slice(beg));
|
return parts;
|
||||||
content = parts.join('\n');
|
},
|
||||||
}
|
|
||||||
return content.trim();
|
|
||||||
};
|
|
||||||
|
|
||||||
µBlock.processDirectives.tokens = new Map([
|
prune: function(content) {
|
||||||
|
const parts = this.split(content);
|
||||||
|
const out = [];
|
||||||
|
for ( let i = 0, n = parts.length - 1; i < n; i += 2 ) {
|
||||||
|
const beg = parts[i+0];
|
||||||
|
const end = parts[i+1];
|
||||||
|
out.push(content.slice(beg, end));
|
||||||
|
}
|
||||||
|
return out.join('\n');
|
||||||
|
},
|
||||||
|
|
||||||
|
tokens: new Map([
|
||||||
[ 'ext_ublock', 'ublock' ],
|
[ 'ext_ublock', 'ublock' ],
|
||||||
[ 'env_chromium', 'chromium' ],
|
[ 'env_chromium', 'chromium' ],
|
||||||
[ 'env_edge', 'edge' ],
|
[ 'env_edge', 'edge' ],
|
||||||
@ -915,7 +926,8 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
[ 'cap_html_filtering', 'html_filtering' ],
|
[ 'cap_html_filtering', 'html_filtering' ],
|
||||||
[ 'cap_user_stylesheet', 'user_stylesheet' ],
|
[ 'cap_user_stylesheet', 'user_stylesheet' ],
|
||||||
[ 'false', 'false' ],
|
[ 'false', 'false' ],
|
||||||
]);
|
]),
|
||||||
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user