From 61300e4dd750d72381346bb3aace3d29809ae97b Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 18 Apr 2013 02:30:16 -0400 Subject: [PATCH 1/2] Try to parse paths as paths in addition to URIs --- .../xpcom/translation/translate_item.js | 107 ++++++++++++------ 1 file changed, 75 insertions(+), 32 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 430b608619..6278da4eba 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -285,45 +285,88 @@ Zotero.Translate.ItemSaver.prototype = { return newItem; }, - - "_parsePath":function(path) { - // generate nsIFile - var IOService = Components.classes["@mozilla.org/network/io-service;1"]. - getService(Components.interfaces.nsIIOService); + + "_parsePathURI":function(path) { try { - var uri = IOService.newURI(Zotero.File.encodeFilePath(path), "", this._baseURI); + var uri = Services.io.newURI(path, "", this._baseURI); + var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file; + if(file.path != '/' && file.exists()) return file; } catch (e) { - var msg = "Error parsing attachment path: " + path + "\n" + e.message; - Zotero.logError(msg); - Zotero.debug("Translate: " + msg, 2); - return false; + Zotero.logError(e); } - + return false; + }, + + "_parseAbsolutePath":function(path) { try { - var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file; - if (file.path == '/') { - var msg = "Error parsing attachment path: " + path + "\nRoot path returned."; - Zotero.logError(msg); - Zotero.debug("Translate: " + msg, 2); - return false; + // First, try to parse absolute paths using initWithPath + var file = Components.classes["@mozilla.org/file/local;1"]. + createInstance(Components.interfaces.nsILocalFile); + file.initWithPath(path); + if(file.exists()) return file; + } catch(e) { + Zotero.logError(e); + } + return false; + }, + + "_parseRelativePath":function(path) { + try { + var file = this._baseURI.QueryInterface(Components.interfaces.nsIFileURL).file.parent; + var splitPath = path.split(/[\/\\]/g); + for(var i=0; i Date: Thu, 18 Apr 2013 02:52:36 -0400 Subject: [PATCH 2/2] Handle pathological case with backslashes in path --- .../zotero/xpcom/translation/translate_item.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 6278da4eba..afab5df4da 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -314,11 +314,10 @@ Zotero.Translate.ItemSaver.prototype = { "_parseRelativePath":function(path) { try { var file = this._baseURI.QueryInterface(Components.interfaces.nsIFileURL).file.parent; - var splitPath = path.split(/[\/\\]/g); + var splitPath = path.split(/\//g); for(var i=0; i