From ec280c5bdf0a9b144c6f4cde4d07bb5599a68730 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 22 Jan 2025 03:14:53 -0500 Subject: [PATCH] Item#fromJSON(): Don't process any Extra rows in `strict` mode And enable migration of Extra rows to valid fields in non-strict mode, but since that's only used by translators now, that probably won't do anything Fixes #3422 --- chrome/content/zotero/xpcom/data/item.js | 46 +++++++++++++----------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 3c22814231..d92616665e 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -5124,6 +5124,7 @@ Zotero.Item.prototype._eraseData = Zotero.Promise.coroutine(function* (env) { */ Zotero.Item.prototype.fromJSON = function (json, options = {}) { var strict = !!options.strict; + var migrateExtra = !strict; if (!json.itemType && !this._itemTypeID) { throw new Error("itemType property not provided"); @@ -5139,29 +5140,34 @@ Zotero.Item.prototype.fromJSON = function (json, options = {}) { var isValidForType = {}; var setFields = new Set(); - 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 a different item type was parsed out of Extra, use that instead - if (itemType && json.itemType != itemType) { - itemTypeID = Zotero.ItemTypes.getID(itemType); - this.setType(itemTypeID); + + var extraFields = new Map(); + var extraCreators = []; + var extra = json.extra || ''; + // Transfer valid fields from Extra to regular fields + if (migrateExtra) { + let itemType; + ({ itemType, fields: extraFields, creators: extraCreators, extra } = + Zotero.Utilities.Internal.extractExtraFields( + extra, + this, + Object.keys(json) + // TEMP until we move creator lines to real creators + .concat('creators') + )); + // If a different item type was parsed out of Extra, use that instead + if (itemType && json.itemType != itemType) { + itemTypeID = Zotero.ItemTypes.getID(itemType); + this.setType(itemTypeID); + } + for (let [field, value] of extraFields) { + this.setField(field, value); + setFields.add(field); + extraFields.delete(field); + } } var invalidFieldLogLines = new Map(); - // Transfer valid fields from Extra to regular fields - // Currently disabled - /*for (let [field, value] of extraFields) { - this.setField(field, value); - setFields.add(field); - extraFields.delete(field); - }*/ - for (let field in json) { let val = json[field];