From 0d5abb018afa33df7092caee5a3a8b581ce3ab87 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 12 Jan 2019 02:34:31 -0500 Subject: [PATCH] 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 --- .../xpcom/translation/translate_item.js | 7 ++++- test/tests/translateTest.js | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index ad4377c342..7140c1b325 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -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} ` diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js index e70ef71ec0..946fffbe88 100644 --- a/test/tests/translateTest.js +++ b/test/tests/translateTest.js @@ -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); + }); }); }); } \ No newline at end of file