This commit is contained in:
Raymond Hill 2017-12-15 09:24:06 -05:00
parent 912582ce4b
commit 8e7ccef14c
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 21 additions and 15 deletions

View File

@ -173,12 +173,12 @@ api.fetchText = function(url, onLoad, onError) {
// Support the seamless loading of sublists.
api.fetchFilterList = function(mainlistURL, onLoad, onError) {
var µburi = µBlock.URI,
content = [],
var content = [],
errored = false,
pendingSublistURLs = new Set([ mainlistURL ]),
loadedSublistURLs = new Set(),
mainOriginURL = µburi.originFromURI(mainlistURL);
toParsedURL = api.fetchFilterList.toParsedURL,
parsedMainURL = toParsedURL(mainlistURL);
var onLocalLoadSuccess = function(details) {
if ( errored ) { return; }
@ -192,21 +192,20 @@ api.fetchFilterList = function(mainlistURL, onLoad, onError) {
content.push(details.content.trim());
if ( isSublist ) { content.push('! <<<<<<<< ' + details.url); }
if ( mainOriginURL !== '' ) {
var subOriginURL,
reInclude = /^!#include (\S+)/gm,
if ( parsedMainURL !== undefined ) {
var reInclude = /^!#include +(\S+)/gm,
match = reInclude.exec(details.content);
while ( match !== null ) {
sublistURL = match[1];
subOriginURL = µburi.originFromURI(sublistURL);
if ( subOriginURL !== '' && subOriginURL !== mainOriginURL ) {
continue;
var parsedSubURL = toParsedURL(match[1]);
if ( parsedSubURL === undefined ) {
parsedSubURL = toParsedURL(
parsedMainURL.href.replace(/[^/?]+(?:\?.*)?$/, match[1])
);
if ( parsedSubURL === undefined ) { continue; }
}
if ( subOriginURL === '' ) {
sublistURL = mainOriginURL + '/' + sublistURL;
}
if ( loadedSublistURLs.has(sublistURL) ) { continue; }
pendingSublistURLs.add(sublistURL);
if ( parsedSubURL.origin !== parsedMainURL.origin ) { continue; }
if ( loadedSublistURLs.has(parsedSubURL.href) ) { continue; }
pendingSublistURLs.add(parsedSubURL.href);
match = reInclude.exec(details.content);
}
}
@ -233,6 +232,13 @@ api.fetchFilterList = function(mainlistURL, onLoad, onError) {
this.fetchText(mainlistURL, onLocalLoadSuccess, onLocalLoadError);
};
api.fetchFilterList.toParsedURL = function(url) {
try {
return new URL(url);
} catch (ex) {
}
};
/*******************************************************************************
The purpose of the asset source registry is to keep key detail information