1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-01 16:33:06 +01:00

Fix parsing of trailing resource

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1419
This commit is contained in:
Raymond Hill 2020-12-28 07:03:52 -05:00
parent 1d2907890b
commit d910111d4a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -349,12 +349,14 @@ RedirectEngine.prototype.resourceContentFromName = function(name, mime) {
// Consider 'none' a reserved keyword, to be used to disable redirection.
RedirectEngine.prototype.resourcesFromString = function(text) {
const lineIter = new µBlock.LineIterator(removeTopCommentBlock(text));
const lineIter = new µBlock.LineIterator(
removeTopCommentBlock(text) + '\n\n'
);
const reNonEmptyLine = /\S/;
let fields, encoded, details;
while ( lineIter.eot() === false ) {
let line = lineIter.next();
const line = lineIter.next();
if ( line.startsWith('#') ) { continue; }
if ( line.startsWith('// ') ) { continue; }
@ -396,18 +398,16 @@ RedirectEngine.prototype.resourcesFromString = function(text) {
continue;
}
// No more data, add the resource.
const name = this.aliases.get(fields[0]) || fields[0];
const mime = fields[1];
const content = µBlock.orphanizeString(
fields.slice(2).join(encoded ? '' : '\n')
);
// No more data, add the resource.
this.resources.set(
name,
RedirectEntry.fromContent(mime, content)
);
if ( Array.isArray(details) ) {
for ( const { prop, value } of details ) {
if ( prop !== 'alias' ) { continue; }
@ -419,22 +419,6 @@ RedirectEngine.prototype.resourcesFromString = function(text) {
details = undefined;
}
// Process pending resource data.
if ( fields !== undefined ) {
const name = fields[0];
const mime = fields[1];
const content = µBlock.orphanizeString(
fields.slice(2).join(encoded ? '' : '\n')
);
this.resources.set(
name,
RedirectEntry.fromContent(mime, content)
);
if ( details instanceof Object && details.alias ) {
this.aliases.set(details.alias, name);
}
}
this.modifyTime = Date.now();
};