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