mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-23 19:03:02 +01:00
Fix loss of newlines when processing pre-parsing directives
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1603
This commit is contained in:
parent
07d3c96261
commit
37ad821018
@ -199,6 +199,14 @@ api.fetchText = async function(url) {
|
|||||||
if ( text.startsWith('<') && text.endsWith('>') ) {
|
if ( text.startsWith('<') && text.endsWith('>') ) {
|
||||||
details.content = '';
|
details.content = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Important: Non empty text resource must always end with a newline
|
||||||
|
if (
|
||||||
|
details.content.length !== 0 &&
|
||||||
|
details.content.endsWith('\n') === false
|
||||||
|
) {
|
||||||
|
details.content += '\n';
|
||||||
|
}
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
details = ex;
|
details = ex;
|
||||||
}
|
}
|
||||||
@ -218,7 +226,7 @@ api.fetchText = async function(url) {
|
|||||||
api.fetchFilterList = async function(mainlistURL) {
|
api.fetchFilterList = async function(mainlistURL) {
|
||||||
const toParsedURL = url => {
|
const toParsedURL = url => {
|
||||||
try {
|
try {
|
||||||
return new URL(url);
|
return new URL(url.trim());
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -249,7 +257,7 @@ api.fetchFilterList = async function(mainlistURL) {
|
|||||||
// `!#if` directive.
|
// `!#if` directive.
|
||||||
const processIncludeDirectives = function(results) {
|
const processIncludeDirectives = function(results) {
|
||||||
const out = [];
|
const out = [];
|
||||||
const reInclude = /^!#include +(\S+)/gm;
|
const reInclude = /^!#include +(\S+)[^\n\r]*(?:[\n\r]+|$)/gm;
|
||||||
for ( const result of results ) {
|
for ( const result of results ) {
|
||||||
if ( typeof result === 'string' ) {
|
if ( typeof result === 'string' ) {
|
||||||
out.push(result);
|
out.push(result);
|
||||||
@ -274,14 +282,14 @@ api.fetchFilterList = async function(mainlistURL) {
|
|||||||
// Compute nested list path relative to parent list path
|
// Compute nested list path relative to parent list path
|
||||||
const pos = result.url.lastIndexOf('/');
|
const pos = result.url.lastIndexOf('/');
|
||||||
if ( pos === -1 ) { continue; }
|
if ( pos === -1 ) { continue; }
|
||||||
const subURL = result.url.slice(0, pos + 1) + match[1];
|
const subURL = result.url.slice(0, pos + 1) + match[1].trim();
|
||||||
if ( sublistURLs.has(subURL) ) { continue; }
|
if ( sublistURLs.has(subURL) ) { continue; }
|
||||||
sublistURLs.add(subURL);
|
sublistURLs.add(subURL);
|
||||||
out.push(
|
out.push(
|
||||||
slice.slice(lastIndex, match.index + match[0].length),
|
slice.slice(lastIndex, match.index + match[0].length),
|
||||||
`! >>>>>>>> ${subURL}`,
|
`! >>>>>>>> ${subURL}\n`,
|
||||||
api.fetchText(subURL),
|
api.fetchText(subURL),
|
||||||
`! <<<<<<<< ${subURL}`
|
`! <<<<<<<< ${subURL}\n`
|
||||||
);
|
);
|
||||||
lastIndex = reInclude.lastIndex;
|
lastIndex = reInclude.lastIndex;
|
||||||
}
|
}
|
||||||
@ -316,7 +324,7 @@ api.fetchFilterList = async function(mainlistURL) {
|
|||||||
url: mainlistURL,
|
url: mainlistURL,
|
||||||
content: allParts.length === 1
|
content: allParts.length === 1
|
||||||
? allParts[0]
|
? allParts[0]
|
||||||
: allParts.map(s => s.trim()).filter(s => s !== '').join('\n') + '\n'
|
: allParts.join('') + '\n'
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user