www

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

commit fcce6327aebcda62d3393d5aed362faffdd2ab28
parent 83cd3c49b0e59b0078e6c92d7ddda855dffa6def
Author: Dan Stillman <dstillman@gmail.com>
Date:   Thu, 21 Mar 2013 01:26:12 -0700

Merge pull request #277 from aurimasv/escape-path

Escape special characters in file paths when attaching files
Diffstat:
Mchrome/content/zotero/xpcom/file.js | 15+++++++++++++++
Mchrome/content/zotero/xpcom/translation/translate_item.js | 8++++----
2 files changed, 19 insertions(+), 4 deletions(-)

diff --git 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<n; i+=2) { + parts[i] = encodeURIComponent(parts[i]); + } + return parts.join(''); + } function getExtension(file){ var pos = file.leafName.lastIndexOf('.'); diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -291,10 +291,10 @@ Zotero.Translate.ItemSaver.prototype = { var IOService = Components.classes["@mozilla.org/network/io-service;1"]. getService(Components.interfaces.nsIIOService); try { - var uri = IOService.newURI(path, "", this._baseURI); + 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;