From f91ca9c18a1ec3fb24b6f3ab7115c42f2da505e5 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Wed, 20 Apr 2022 11:04:24 -0700 Subject: [PATCH] Don't merge with a deleted master attachment --- chrome/content/zotero/xpcom/data/items.js | 4 ++-- test/tests/itemsTest.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 45f4973daf..4a95c433cd 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -1044,7 +1044,7 @@ Zotero.Items = function() { let matchingHash = await otherAttachment.attachmentHash; let masterAttachmentID = masterAttachmentHashes.get(matchingHash); - if (!masterAttachmentID && item.numAttachments(true)) { + if (!masterAttachmentID && item.numAttachments()) { // If that didn't work, hash master attachments by the // most common words in their text and check again. if (!hashesIncludeText) { @@ -1184,7 +1184,7 @@ Zotero.Items = function() { throw new Error('Invalid hash type'); } - let attachments = (await this.getAsync(item.getAttachments(true))) + let attachments = (await this.getAsync(item.getAttachments())) .filter(attachment => attachment.isFileAttachment()); let hashes = new Map(); await Promise.all(attachments.map(async (attachment) => { diff --git a/test/tests/itemsTest.js b/test/tests/itemsTest.js index abbbf470cb..8380286f6c 100644 --- a/test/tests/itemsTest.js +++ b/test/tests/itemsTest.js @@ -886,6 +886,26 @@ describe("Zotero.Items", function () { assert.isFalse(attachment2.deleted); assert.equal(attachment2.parentItemID, item1.id); }); + + it("should not merge an attachment with a deleted master attachment", async function () { + let item1 = await createDataObject('item', { setTitle: true }); + let attachment1 = await importPDFAttachment(item1); + attachment1.deleted = true; + await attachment1.saveTx(); + + let item2 = item1.clone(); + await item2.saveTx(); + let attachment2 = await importPDFAttachment(item2); + + await Zotero.Items.merge(item1, [item2]); + + assert.isFalse(item1.deleted); + assert.isTrue(attachment1.deleted); + assert.equal(item1.numAttachments(true), 2); + assert.isTrue(item2.deleted); + assert.isFalse(attachment2.deleted); + assert.equal(attachment2.parentItemID, item1.id); + }); })