mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-18 17:02:27 +02:00
Compute URL of sublists as relative to URL of parent list
Related issue: - https://github.com/NanoAdblocker/NanoCore/issues/239 The erroneous behavior was to compute the URL of a sublist as relative to the URL of the root list, which may differ from the URL of a parent list.
This commit is contained in:
parent
3195f554f7
commit
923c5ce5bd
@ -179,7 +179,19 @@ api.fetchFilterList = function(mainlistURL, onLoad, onError) {
|
|||||||
const pendingSublistURLs = new Set([ mainlistURL ]);
|
const pendingSublistURLs = new Set([ mainlistURL ]);
|
||||||
const loadedSublistURLs = new Set();
|
const loadedSublistURLs = new Set();
|
||||||
const toParsedURL = api.fetchFilterList.toParsedURL;
|
const toParsedURL = api.fetchFilterList.toParsedURL;
|
||||||
const parsedURL = toParsedURL(mainlistURL);
|
|
||||||
|
// https://github.com/NanoAdblocker/NanoCore/issues/239
|
||||||
|
// Anything under URL's root directory is allowed to be fetched. The
|
||||||
|
// URL of a sublist will always be relative to the URL of the parent
|
||||||
|
// list (instead of the URL of the root list).
|
||||||
|
const rootDirectoryURL = toParsedURL(mainlistURL);
|
||||||
|
if ( rootDirectoryURL !== undefined ) {
|
||||||
|
const pos = rootDirectoryURL.pathname.lastIndexOf('/');
|
||||||
|
if ( pos !== -1 ) {
|
||||||
|
rootDirectoryURL.pathname =
|
||||||
|
rootDirectoryURL.pathname.slice(0, pos + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let errored = false;
|
let errored = false;
|
||||||
|
|
||||||
@ -193,13 +205,16 @@ api.fetchFilterList = function(mainlistURL, onLoad, onError) {
|
|||||||
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; }
|
||||||
const subURL = parsedURL.origin +
|
const subURL = toParsedURL(details.url);
|
||||||
parsedURL.pathname.replace(/[^/]+$/, match[1]);
|
subURL.pathname = subURL.pathname.replace(/[^/]+$/, match[1]);
|
||||||
if ( pendingSublistURLs.has(subURL) ) { continue; }
|
if ( subURL.href.startsWith(rootDirectoryURL.href) === false ) {
|
||||||
if ( loadedSublistURLs.has(subURL) ) { continue; }
|
continue;
|
||||||
pendingSublistURLs.add(subURL);
|
}
|
||||||
api.fetchText(subURL, onLocalLoadSuccess, onLocalLoadError);
|
if ( pendingSublistURLs.has(subURL.href) ) { continue; }
|
||||||
out.push(content.slice(lastIndex, match.index).trim(), subURL);
|
if ( loadedSublistURLs.has(subURL.href) ) { continue; }
|
||||||
|
pendingSublistURLs.add(subURL.href);
|
||||||
|
api.fetchText(subURL.href, onLocalLoadSuccess, onLocalLoadError);
|
||||||
|
out.push(content.slice(lastIndex, match.index).trim(), subURL.href);
|
||||||
lastIndex = reInclude.lastIndex;
|
lastIndex = reInclude.lastIndex;
|
||||||
}
|
}
|
||||||
out.push(lastIndex === 0 ? content : content.slice(lastIndex).trim());
|
out.push(lastIndex === 0 ? content : content.slice(lastIndex).trim());
|
||||||
@ -231,7 +246,10 @@ api.fetchFilterList = function(mainlistURL, onLoad, onError) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find and process #!include directives
|
// Find and process #!include directives
|
||||||
if ( parsedURL !== undefined && parsedURL.pathname.length > 0 ) {
|
if (
|
||||||
|
rootDirectoryURL !== undefined &&
|
||||||
|
rootDirectoryURL.pathname.length > 0
|
||||||
|
) {
|
||||||
const processed = processIncludeDirectives(details);
|
const processed = processIncludeDirectives(details);
|
||||||
if ( processed.length > 1 ) {
|
if ( processed.length > 1 ) {
|
||||||
content.splice(slot, 1, ...processed);
|
content.splice(slot, 1, ...processed);
|
||||||
|
Loading…
Reference in New Issue
Block a user