Merge pull request #166 from aurimasv/attachments

Allow relative file attachment import. Fix some bugs in _parsePath.
This commit is contained in:
Simon Kornblith 2012-09-21 16:51:10 -07:00
commit c70fd9fa39

View file

@ -204,7 +204,7 @@ Zotero.Translate.ItemSaver.prototype = {
},
"_saveAttachmentFile":function(attachment, parentID) {
const urlRe = /(([A-Za-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) {
@ -215,7 +215,7 @@ 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() : "";
var protocol = m ? m[2].toLowerCase() : "file";
if(protocol == "file") {
attachment.path = attachment.url;
attachment.url = false;
@ -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;