Ignore invalid paths during export

Invalid paths, including Windows UNC paths on other OSes, caused exports
to fail. Now they're ignored, which is what we do for other missing
attachment files.

Fixes #1622
This commit is contained in:
Dan Stillman 2019-01-12 02:34:31 -05:00
parent 9c0f5998a3
commit 0d5abb018a
2 changed files with 33 additions and 1 deletions

View file

@ -1014,7 +1014,12 @@ Zotero.Translate.ItemGetter.prototype = {
// Add path and filename if not an internet link
let attachFile;
if (attachmentArray.localPath) {
attachFile = Zotero.File.pathToFile(attachmentArray.localPath);
try {
attachFile = Zotero.File.pathToFile(attachmentArray.localPath);
}
catch (e) {
Zotero.logError(e);
}
}
else {
Zotero.logError(`Path doesn't exist for attachment ${attachment.libraryKey} `

View file

@ -1804,6 +1804,33 @@ describe("Zotero.Translate.ItemGetter", function() {
var exportFile = OS.Path.join(exportDir, 'export.rdf');
assert.isAbove((yield OS.File.stat(exportFile)).size, 0);
});
it("should handle UNC paths", async function () {
var path = '\\\\SHARE\\test.png';
var attachment = await Zotero.Attachments.linkFromFile({
file: OS.Path.join(getTestDataDirectory().path, 'test.png')
});
attachment._attachmentPath = path;
assert.equal(attachment.attachmentPath, path);
var translation = new Zotero.Translate.Export();
var tmpDir = await getTempDirectory();
var exportDir = OS.Path.join(tmpDir, 'export');
translation.setLocation(Zotero.File.pathToFile(exportDir));
translation.setItems([attachment]);
translation.setTranslator('14763d24-8ba0-45df-8f52-b8d1108e7ac9'); // Zotero RDF
translation.setDisplayOptions({
exportFileData: true
});
await translation.translate();
var exportFile = OS.Path.join(exportDir, 'export.rdf');
assert.isAbove((await OS.File.stat(exportFile)).size, 0);
var rdf = Zotero.File.getContents(exportFile);
var dp = new DOMParser();
var doc = dp.parseFromString(rdf, 'text/xml');
assert.equal(doc.querySelector('resource').getAttribute('rdf:resource'), path);
});
});
});
}