code hardening: let's consider an empty file an invalid file

This commit is contained in:
gorhill 2014-09-03 20:29:05 -04:00
parent c0aadc1972
commit 88596cb855
1 changed files with 7 additions and 12 deletions

View File

@ -371,32 +371,27 @@ var readLocalFile = function(path, callback) {
}; };
var onInstallFileLoaded = function() { var onInstallFileLoaded = function() {
this.onload = this.onerror = null;
//console.log('µBlock> readLocalFile("%s") / onInstallFileLoaded()', path); //console.log('µBlock> readLocalFile("%s") / onInstallFileLoaded()', path);
reportBack(this.responseText); reportBack(this.responseText);
this.onload = this.onerror = null;
}; };
var onInstallFileError = function() { var onInstallFileError = function() {
this.onload = this.onerror = null;
console.error('µBlock> readLocalFile("%s") / onInstallFileError()', path); console.error('µBlock> readLocalFile("%s") / onInstallFileError()', path);
reportBack('', 'Error'); reportBack('', 'Error');
this.onload = this.onerror = null;
}; };
var onCachedContentLoaded = function(details) { var onCachedContentReady = function(details) {
//console.log('µBlock> readLocalFile("%s") / onCachedContentLoaded()', path); //console.log('µBlock> readLocalFile("%s") / onCachedContentReady()', path);
reportBack(details.content); if ( !details.error && details.content !== '' ) {
}; reportBack(details.content);
var onCachedContentError = function(details) {
//console.error('µBlock> readLocalFile("%s") / onCachedContentError()', path);
if ( reIsExternalPath.test(path) ) {
reportBack('', 'Error: asset not found');
return; return;
} }
getTextFileFromURL(chrome.runtime.getURL(details.path), onInstallFileLoaded, onInstallFileError); getTextFileFromURL(chrome.runtime.getURL(details.path), onInstallFileLoaded, onInstallFileError);
}; };
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError); cachedAssetsManager.load(path, onCachedContentReady);
}; };
// https://www.youtube.com/watch?v=r9KVpuFPtHc // https://www.youtube.com/watch?v=r9KVpuFPtHc