From d6bd35300506c5ae7a344d27950f2726e7c752ef Mon Sep 17 00:00:00 2001 From: aurimasv Date: Thu, 13 Sep 2012 22:51:08 -0500 Subject: [PATCH 1/3] Allow relative file attachment import. Fix some bugs in _parsePath. --- .../content/zotero/xpcom/translation/translate_item.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index b7340099d..0b79313b9 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -204,7 +204,7 @@ Zotero.Translate.ItemSaver.prototype = { }, "_saveAttachmentFile":function(attachment, parentID) { - const urlRe = /(([A-Za-z]+):\/\/[^\s]*)/i; + const urlRe = /(([a-z]+):\/\/[^\s]*)/i; Zotero.debug("Translate: Adding attachment", 4); if(!attachment.url && !attachment.path) { @@ -216,7 +216,7 @@ Zotero.Translate.ItemSaver.prototype = { // see if this is actually a file URL var m = urlRe.exec(attachment.url); var protocol = m ? m[2].toLowerCase() : ""; - if(protocol == "file") { + if(protocol == "file" || protocol == "") { attachment.path = attachment.url; attachment.url = false; } else if(protocol != "http" && protocol != "https") { @@ -275,7 +275,7 @@ Zotero.Translate.ItemSaver.prototype = { var uri = IOService.newURI(path, "", this._baseURI); } catch (e) { - var msg = "Error parsing attachment path: " + attachment.path; + var msg = "Error parsing attachment path: " + path; Zotero.logError(msg); Zotero.debug("Translate: " + msg, 2); return false; @@ -284,14 +284,14 @@ Zotero.Translate.ItemSaver.prototype = { try { var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file; if (file.path == '/') { - var msg = "Error parsing attachment path: " + attachment.path; + var msg = "Error parsing attachment path: " + path; Zotero.logError(msg); Zotero.debug("Translate: " + msg, 2); return false; } } catch (e) { - var msg = "Error getting file from attachment path: " + attachment.path; + var msg = "Error getting file from attachment path: " + path; Zotero.logError(msg); Zotero.debug("Translate: " + msg, 2); return false; From b94837d3da334b273536099425dd852d7b59a7d3 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Fri, 14 Sep 2012 02:21:54 -0500 Subject: [PATCH 2/3] Recognize URI protocol based on RFC 3986 specification --- chrome/content/zotero/xpcom/translation/translate_item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 0b79313b9..777d93f28 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -204,7 +204,7 @@ Zotero.Translate.ItemSaver.prototype = { }, "_saveAttachmentFile":function(attachment, parentID) { - const urlRe = /(([a-z]+):\/\/[^\s]*)/i; + const urlRe = /(([a-z][-+\.a-z0-9]*):\/\/[^\s]*)/i; //according to RFC3986 Zotero.debug("Translate: Adding attachment", 4); if(!attachment.url && !attachment.path) { From cffbed31e837af6dcc85234f715410e1b44a87bf Mon Sep 17 00:00:00 2001 From: aurimasv Date: Fri, 14 Sep 2012 20:09:58 -0500 Subject: [PATCH 3/3] Make protocol decision clearer --- chrome/content/zotero/xpcom/translation/translate_item.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 777d93f28..64e5e6089 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -215,8 +215,8 @@ Zotero.Translate.ItemSaver.prototype = { if(!attachment.path) { // see if this is actually a file URL var m = urlRe.exec(attachment.url); - var protocol = m ? m[2].toLowerCase() : ""; - if(protocol == "file" || protocol == "") { + var protocol = m ? m[2].toLowerCase() : "file"; + if(protocol == "file") { attachment.path = attachment.url; attachment.url = false; } else if(protocol != "http" && protocol != "https") {