Handle invalid filenames without failure during import
Export should be fixed to run exported filenames through getValidFileName()
This commit is contained in:
parent
e0c8e30161
commit
eec491fe7a
1 changed files with 21 additions and 8 deletions
|
@ -1513,21 +1513,34 @@ Zotero.Translate.prototype._itemDone = function(item, attachedTo) {
|
||||||
Zotero.debug("Translate: Created attachment; id is "+myID, 4);
|
Zotero.debug("Translate: Created attachment; id is "+myID, 4);
|
||||||
var newItem = Zotero.Items.get(myID);
|
var newItem = Zotero.Items.get(myID);
|
||||||
} else {
|
} else {
|
||||||
|
var uri, file;
|
||||||
|
|
||||||
// generate nsIFile
|
// generate nsIFile
|
||||||
var IOService = Components.classes["@mozilla.org/network/io-service;1"].
|
var IOService = Components.classes["@mozilla.org/network/io-service;1"].
|
||||||
getService(Components.interfaces.nsIIOService);
|
getService(Components.interfaces.nsIIOService);
|
||||||
var uri = IOService.newURI(item.path, "", null);
|
try {
|
||||||
var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file;
|
var uri = IOService.newURI(item.path, "", null);
|
||||||
|
}
|
||||||
if (file.path == '/') {
|
catch (e) {
|
||||||
Zotero.debug("Translate: Ignoring attachment '" + item.path + "': error parsing path", 2);
|
Components.utils.reportError("Error parsing attachment path: " + item.path);
|
||||||
return;
|
Zotero.debug("Translate: Error parsing attachment path '" + item.path + "'", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (uri) {
|
||||||
|
var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file;
|
||||||
|
|
||||||
|
if (file.path == '/') {
|
||||||
|
Components.utils.reportError("Error parsing attachment path: " + item.path);
|
||||||
|
Zotero.debug("Translate: Error parsing attachment attachment '" + item.path + "'", 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file || !file.exists()) {
|
||||||
// use item title if possible, or else file leaf name
|
// use item title if possible, or else file leaf name
|
||||||
var title = item.title;
|
var title = item.title;
|
||||||
if(!title) title = file.leafName;
|
if(!title) {
|
||||||
|
title = file ? file.leafName : '';
|
||||||
|
}
|
||||||
|
|
||||||
var myID = Zotero.Attachments.createMissingAttachment(
|
var myID = Zotero.Attachments.createMissingAttachment(
|
||||||
item.url ? Zotero.Attachments.LINK_MODE_IMPORTED_URL
|
item.url ? Zotero.Attachments.LINK_MODE_IMPORTED_URL
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue