diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 4e738644a3..7853622a54 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -4871,12 +4871,14 @@ Zotero.Item.prototype.fromJSON = function (json, options = {}) { } // Both notes and attachments might have parents and notes - if (this.isNote() || this.isAttachment()) { + if (this.isNote() || this.isAttachment() || this.isAnnotation()) { let parentKey = json.parentItem; this.parentKey = parentKey ? parentKey : false; - let note = json.note; - this.setNote(note !== undefined ? note : "", json.noteSchemaVersion); + if (!this.isAnnotation()) { + let note = json.note; + this.setNote(note !== undefined ? note : "", json.noteSchemaVersion); + } } // Update boolean fields that might not be present in JSON diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index 5b41f389d9..06d7320ecc 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -2393,10 +2393,14 @@ describe("Zotero.Item", function () { assert.equal(item.noteSchemaVersion, 3); }); - it("should import annotation fields", function () { + it("should import annotation fields", async function () { + var attachment = await importPDFAttachment(); + var item = new Zotero.Item(); + item.libraryID = attachment.libraryID; var json = { itemType: "annotation", + parentItem: attachment.key, annotationType: 'highlight', annotationText: "This is highlighted text.", annotationComment: "This is a comment with rich-text\nAnd a new line", @@ -2418,6 +2422,9 @@ describe("Zotero.Item", function () { if (i == 'tags') { assert.deepEqual(item.getTags(), json[i]); } + else if (i == 'parentItem') { + assert.equal(item.parentKey, json[i]); + } else { assert.equal(item[i], json[i]); }