Item merging: Don't merge web link attachments with different URLs
Some checks are pending
CI / Detect changes (push) Waiting to run
CI / Test () (push) Blocked by required conditions
CI / Test (macOS NFS) (push) Blocked by required conditions
CI / Test (Windows arm64) (push) Blocked by required conditions
CI / Test (Windows x64) (push) Blocked by required conditions
CI / Utilities Tests (push) Waiting to run
CI / Build, Upload (push) Waiting to run

https://forums.zotero.org/discussion/133795
This commit is contained in:
Abe Jellinek 2026-09-23 13:53:08 -04:00
parent 22a26bb483
commit ed8ca1bfce
2 changed files with 31 additions and 2 deletions

View file

@ -240,12 +240,14 @@ async function mergeWebAttachments(item, otherItems) {
}
// If we can find an attachment with the same title *and* URL, use it.
// For snapshots, fall back to matching on title alone.
let masterAttachment = (
masterAttachments.find(attachment => attachment.getField('title') == otherAttachment.getField('title')
&& attachment.getField('url') == otherAttachment.getField('url')
&& attachment.attachmentLinkMode === otherAttachment.attachmentLinkMode)
|| masterAttachments.find(attachment => attachment.getField('title') == otherAttachment.getField('title')
&& attachment.attachmentLinkMode === otherAttachment.attachmentLinkMode)
|| otherAttachment.attachmentLinkMode !== Zotero.Attachments.LINK_MODE_LINKED_URL
&& masterAttachments.find(attachment => attachment.getField('title') == otherAttachment.getField('title')
&& attachment.attachmentLinkMode === otherAttachment.attachmentLinkMode)
);
if (!masterAttachment) {

View file

@ -573,6 +573,33 @@ describe("Item merging", function () {
assert.isFalse(attachment3.deleted);
});
it("should keep linked URL with same title but different URL", async function () {
let item1 = await createDataObject('item', { setTitle: true });
let attachment1 = await Zotero.Attachments.linkFromURL({
url: 'https://example.com/',
title: 'Catalog Entry',
parentItemID: item1.id
});
let item2 = item1.clone();
await item2.saveTx();
let attachment2 = await Zotero.Attachments.linkFromURL({
url: 'https://otherdomain.example.com/',
title: 'Catalog Entry',
parentItemID: item2.id
});
await mergeItems(item1, [item2]);
assert.isFalse(item1.deleted);
assert.isFalse(attachment1.deleted);
assert.equal(item1.numAttachments(true), 2);
assert.isTrue(item2.deleted);
assert.equal(attachment2.parentItemID, item1.id);
assert.isFalse(attachment2.deleted);
assert.equal(attachment2.getField('url'), 'https://otherdomain.example.com/');
});
it("should keep web attachment with same URL but different title", async function () {
let item1 = await createDataObject('item', { setTitle: true });
let attachment1 = await Zotero.Attachments.linkFromURL({