From d910111d4ad42b27b9604d08139defdc116744a8 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 28 Dec 2020 07:03:52 -0500 Subject: [PATCH] Fix parsing of trailing resource Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1419 --- src/js/redirect-engine.js | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/js/redirect-engine.js b/src/js/redirect-engine.js index 5d8fd8a7b..131b9b11c 100644 --- a/src/js/redirect-engine.js +++ b/src/js/redirect-engine.js @@ -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(); };