www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 135c47944d4485413c81ead431aa2e14e6c95dd2
parent 78e9d09f4ddfbebe794732a38cbe26983a20e773
Author: Simon Kornblith <simon@simonster.com>
Date:   Mon, 21 Mar 2011 22:45:15 +0000

better handling of invalid regular expressions


Diffstat:
Mchrome/content/zotero/xpcom/translation/translator.js | 26+++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/chrome/content/zotero/xpcom/translation/translator.js b/chrome/content/zotero/xpcom/translation/translator.js @@ -298,12 +298,13 @@ Zotero.Translator = function(file, json, code) { this.file = file; + var fStream, cStream; if(json) { var info = Zotero.JSON.unserialize(json); } else { - var fStream = Components.classes["@mozilla.org/network/file-input-stream;1"]. + fStream = Components.classes["@mozilla.org/network/file-input-stream;1"]. createInstance(Components.interfaces.nsIFileInputStream); - var cStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]. + cStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]. createInstance(Components.interfaces.nsIConverterInputStream); fStream.init(file, -1, -1, 0); cStream.init(fStream, "UTF-8", 8192, @@ -352,7 +353,7 @@ Zotero.Translator = function(file, json, code) { } } if(!haveMetadata) { - fStream.close(); + if(fStream) fStream.close(); return; } @@ -362,13 +363,28 @@ Zotero.Translator = function(file, json, code) { if(this.translatorType & TRANSLATOR_TYPES["import"]) { // compile import regexp to match only file extension - this.importRegexp = this.target ? new RegExp("\\."+this.target+"$", "i") : null; + try { + this.importRegexp = this.target ? new RegExp("\\."+this.target+"$", "i") : null; + } catch(e) { + this.logError("Invalid target in " + file.leafName); + this.importRegexp = null; + if(fStream) fStream.close(); + return; + } } this.cacheCode = false; if(this.translatorType & TRANSLATOR_TYPES["web"]) { // compile web regexp - this.webRegexp = this.target ? new RegExp(this.target, "i") : null; + try { + this.webRegexp = this.target ? new RegExp(this.target, "i") : null; + } catch(e) { + if(fStream) fStream.close(); + this.logError("Invalid target in " + file.leafName); + this.webRegexp = null; + if(fStream) fStream.close(); + return; + } if(!this.target) { this.cacheCode = true;