diff --git a/.eslintrc b/.eslintrc index debaefdb24..c884555ba4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,6 +8,7 @@ "Zotero": false, "ZOTERO_CONFIG": false, "AddonManager": false, + "assert": false, "Cc": false, "Ci": false, "Components": false, diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index b1cd971849..1d7b786c9e 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -495,7 +495,7 @@ Zotero.Translate.ItemSaver.prototype = { let newAttachment; // determine whether to save files and attachments - let isLink = Zotero.MIME.isWebPageType(attachment.mimeType) + var isLink = Zotero.MIME.isWebPageType(attachment.mimeType) // .snapshot coming from most translators, .linkMode coming from RDF && (attachment.snapshot === false || attachment.linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL); if (isLink || this.attachmentMode == Zotero.Translate.ItemSaver.ATTACHMENT_MODE_DOWNLOAD) { @@ -597,7 +597,7 @@ Zotero.Translate.ItemSaver.prototype = { } // At this point, must be a valid HTTP/HTTPS url - attachment.linkMode = "linked_file"; + attachment.linkMode = "linked_url"; newItem = yield Zotero.Attachments.linkFromURL({ url: attachment.url, parentItemID, @@ -775,7 +775,9 @@ Zotero.Translate.ItemSaver.prototype = { // Commit to saving attachmentCallback(attachment, 0); - if(attachment.snapshot === false || this.attachmentMode === Zotero.Translate.ItemSaver.ATTACHMENT_MODE_IGNORE) { + var isLink = attachment.snapshot === false + || attachment.linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL; + if (isLink || this.attachmentMode === Zotero.Translate.ItemSaver.ATTACHMENT_MODE_IGNORE) { // if snapshot is explicitly set to false, attach as link attachment.linkMode = "linked_url"; let url, mimeType; diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js index 946fffbe88..0e19cbb312 100644 --- a/test/tests/translateTest.js +++ b/test/tests/translateTest.js @@ -1,5 +1,6 @@ new function() { Components.utils.import("resource://gre/modules/osfile.jsm"); +Components.utils.import("resource://zotero-unit/httpd.js"); /** * Create a new translator that saves the specified items @@ -405,6 +406,65 @@ describe("Zotero.Translate", function() { assert.equal(newItems[0].getAttachments().length, 0); }); + it('import translators should save link attachments', async function () { + // Start a local server so we can make sure a web request isn't made for the URL + var port = 16213; + var baseURL = `http://127.0.0.1:${port}/`; + var httpd = new HttpServer(); + httpd.start(port); + var callCount = 0; + var handler = function (_request, response) { + callCount++; + response.setStatusLine(null, 200, "OK"); + response.write("