Fix `!#include` directive when loading from packaged lists

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1034
This commit is contained in:
Raymond Hill 2020-05-15 18:06:14 -04:00
parent 0d5f8e8fb2
commit 8ceed3d4ca
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 11 additions and 11 deletions

View File

@ -227,7 +227,11 @@ api.fetchFilterList = async function(mainlistURL) {
// Anything under URL's root directory is allowed to be fetched. The // 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 // URL of a sublist will always be relative to the URL of the parent
// list (instead of the URL of the root list). // list (instead of the URL of the root list).
let rootDirectoryURL = toParsedURL(mainlistURL); let rootDirectoryURL = toParsedURL(
reIsExternalPath.test(mainlistURL)
? mainlistURL
: vAPI.getURL(mainlistURL)
);
if ( rootDirectoryURL !== undefined ) { if ( rootDirectoryURL !== undefined ) {
const pos = rootDirectoryURL.pathname.lastIndexOf('/'); const pos = rootDirectoryURL.pathname.lastIndexOf('/');
if ( pos !== -1 ) { if ( pos !== -1 ) {
@ -257,18 +261,14 @@ api.fetchFilterList = async function(mainlistURL) {
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 = toParsedURL(result.url); const subURL = rootDirectoryURL.href + match[1];
subURL.pathname = subURL.pathname.replace(/[^/]+$/, match[1]); if ( sublistURLs.has(subURL) ) { continue; }
if ( subURL.href.startsWith(rootDirectoryURL.href) === false ) { sublistURLs.add(subURL);
continue;
}
if ( sublistURLs.has(subURL.href) ) { continue; }
sublistURLs.add(subURL.href);
out.push( out.push(
content.slice(lastIndex, match.index), content.slice(lastIndex, match.index),
`! >>>>>>>> ${subURL.href}`, `! >>>>>>>> ${subURL}`,
api.fetchText(subURL.href), api.fetchText(subURL),
`! <<<<<<<< ${subURL.href}` `! <<<<<<<< ${subURL}`
); );
lastIndex = reInclude.lastIndex; lastIndex = reInclude.lastIndex;
} }