From 82448c4a4d367e4e17382ae0c458bdaef3e59d45 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Thu, 21 Mar 2013 03:24:47 -0500 Subject: [PATCH 1/2] Escape special characters in file paths when attaching files --- chrome/content/zotero/xpcom/file.js | 15 +++++++++++++++ .../zotero/xpcom/translation/translate_item.js | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 084c56bf9..57688d467 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -43,6 +43,21 @@ Zotero.File = new function(){ this.getCharsetFromFile = getCharsetFromFile; this.addCharsetListener = addCharsetListener; + /** + * Encode special characters in file paths that might cause problems, + * like # (but preserve slashes or colons) + * + * @param {String} path File path + * @return {String} Encoded file path + */ + this.encodeFilePath = function(path) { + var parts = path.split(/([\\\/:]+)/); + // Every other item is the separator + for (var i=0, n=parts.length; i Date: Thu, 21 Mar 2013 02:42:29 -0500 Subject: [PATCH 2/2] Show error message when attaching file fails. --- chrome/content/zotero/xpcom/translation/translate_item.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index d30c65ed7..aca7e6438 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -294,7 +294,7 @@ Zotero.Translate.ItemSaver.prototype = { var uri = IOService.newURI(Zotero.File.encodeFilePath(path), "", this._baseURI); } catch (e) { - var msg = "Error parsing attachment path: " + path; + var msg = "Error parsing attachment path: " + path + "\n" + e.message; Zotero.logError(msg); Zotero.debug("Translate: " + msg, 2); return false; @@ -303,14 +303,14 @@ Zotero.Translate.ItemSaver.prototype = { try { var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file; if (file.path == '/') { - var msg = "Error parsing attachment path: " + path; + var msg = "Error parsing attachment path: " + path + "\nRoot path returned."; Zotero.logError(msg); Zotero.debug("Translate: " + msg, 2); return false; } } catch (e) { - var msg = "Error getting file from attachment path: " + path; + var msg = "Error getting file from attachment path: " + path + "\n" + e.message; Zotero.logError(msg); Zotero.debug("Translate: " + msg, 2); return false;