From eec491fe7ad6d8eff70f574769f928bb82443eba Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 25 Aug 2010 16:21:49 +0000 Subject: [PATCH] Handle invalid filenames without failure during import Export should be fixed to run exported filenames through getValidFileName() --- chrome/content/zotero/xpcom/translate.js | 29 +++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/xpcom/translate.js b/chrome/content/zotero/xpcom/translate.js index 16a76bc35..cd9e49bed 100644 --- a/chrome/content/zotero/xpcom/translate.js +++ b/chrome/content/zotero/xpcom/translate.js @@ -1513,21 +1513,34 @@ Zotero.Translate.prototype._itemDone = function(item, attachedTo) { Zotero.debug("Translate: Created attachment; id is "+myID, 4); var newItem = Zotero.Items.get(myID); } else { + var uri, file; + // generate nsIFile var IOService = Components.classes["@mozilla.org/network/io-service;1"]. getService(Components.interfaces.nsIIOService); - var uri = IOService.newURI(item.path, "", null); - var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file; - - if (file.path == '/') { - Zotero.debug("Translate: Ignoring attachment '" + item.path + "': error parsing path", 2); - return; + try { + var uri = IOService.newURI(item.path, "", null); + } + catch (e) { + Components.utils.reportError("Error parsing attachment path: " + item.path); + Zotero.debug("Translate: Error parsing attachment path '" + item.path + "'", 2); } - if (!file.exists()) { + if (uri) { + var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file; + + if (file.path == '/') { + Components.utils.reportError("Error parsing attachment path: " + item.path); + Zotero.debug("Translate: Error parsing attachment attachment '" + item.path + "'", 2); + } + } + + if (!file || !file.exists()) { // use item title if possible, or else file leaf name var title = item.title; - if(!title) title = file.leafName; + if(!title) { + title = file ? file.leafName : ''; + } var myID = Zotero.Attachments.createMissingAttachment( item.url ? Zotero.Attachments.LINK_MODE_IMPORTED_URL