From 88596cb8552dc51d8d8be40a1f0b1a4837015715 Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 3 Sep 2014 20:29:05 -0400 Subject: [PATCH] code hardening: let's consider an empty file an invalid file --- js/assets.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/js/assets.js b/js/assets.js index d3d47d609..6f66c7eaf 100644 --- a/js/assets.js +++ b/js/assets.js @@ -371,32 +371,27 @@ var readLocalFile = function(path, callback) { }; var onInstallFileLoaded = function() { + this.onload = this.onerror = null; //console.log('µBlock> readLocalFile("%s") / onInstallFileLoaded()', path); reportBack(this.responseText); - this.onload = this.onerror = null; }; var onInstallFileError = function() { + this.onload = this.onerror = null; console.error('µBlock> readLocalFile("%s") / onInstallFileError()', path); reportBack('', 'Error'); - this.onload = this.onerror = null; }; - var onCachedContentLoaded = function(details) { - //console.log('µBlock> readLocalFile("%s") / onCachedContentLoaded()', path); - reportBack(details.content); - }; - - var onCachedContentError = function(details) { - //console.error('µBlock> readLocalFile("%s") / onCachedContentError()', path); - if ( reIsExternalPath.test(path) ) { - reportBack('', 'Error: asset not found'); + var onCachedContentReady = function(details) { + //console.log('µBlock> readLocalFile("%s") / onCachedContentReady()', path); + if ( !details.error && details.content !== '' ) { + reportBack(details.content); return; } getTextFileFromURL(chrome.runtime.getURL(details.path), onInstallFileLoaded, onInstallFileError); }; - cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError); + cachedAssetsManager.load(path, onCachedContentReady); }; // https://www.youtube.com/watch?v=r9KVpuFPtHc