www

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

commit 82448c4a4d367e4e17382ae0c458bdaef3e59d45
parent 41e2f3008e50fd2803a3c22cb43ed8c9f00714a5
Author: aurimasv <aurimas.dev@gmail.com>
Date:   Thu, 21 Mar 2013 03:24:47 -0500

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 | 2+-
2 files changed, 16 insertions(+), 1 deletion(-)

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,7 +291,7 @@ 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;