diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 7101ccf33e..0217e2a1c5 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -4239,13 +4239,18 @@ Zotero.Item.prototype.fromJSON = function (json, options = {}) { var isValidForType = {}; var setFields = new Set(); - var { fields: extraFields, creators: extraCreators, extra } = Zotero.Utilities.Internal.extractExtraFields( - json.extra || '', - this, - Object.keys(json) - // TEMP until we move creator lines to real creators - .concat('creators') - ); + var { itemType, fields: extraFields, creators: extraCreators, extra } = + Zotero.Utilities.Internal.extractExtraFields( + json.extra || '', + this, + Object.keys(json) + // TEMP until we move creator lines to real creators + .concat('creators') + ); + if (json.itemType != itemType) { + itemTypeID = Zotero.ItemTypes.getID(itemType); + this.setType(itemTypeID); + } var invalidFieldLogLines = new Map(); // Transfer valid fields from Extra to regular fields diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index 8ad0402e84..650da004c7 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -1883,6 +1883,19 @@ describe("Zotero.Item", function () { assert.equal(item.getField('extra'), `doi: ${doi2}`); });*/ + it("should use valid CSL type from Extra", function () { + var json = { + itemType: "journalArticle", + pages: "123", + extra: "Type: song" + }; + var item = new Zotero.Item; + item.fromJSON(json); + assert.equal(item.itemTypeID, Zotero.ItemTypes.getID('audioRecording')); + // A field valid for the old item type should be moved to Extra + assert.equal(item.getField('extra'), 'Pages: 123'); + }); + it("should ignore creator field in Extra", async function () { var json = { itemType: "journalArticle",