Ignore unknown fields in Zotero.Item::fromJSON()

This commit is contained in:
Dan Stillman 2015-11-12 17:24:03 -05:00
parent 3025123cb8
commit 6d64526648
2 changed files with 18 additions and 1 deletions

View file

@ -3819,12 +3819,18 @@ Zotero.Item.prototype.fromJSON = function (json) {
// Item fields
default:
let fieldID = Zotero.ItemFields.getID(field);
if (!fieldID) {
Zotero.logError("Discarding unknown JSON field " + field + " for item "
+ this.libraryKey);
continue;
}
isValidForType[field] = Zotero.ItemFields.isValidForType(
Zotero.ItemFields.getFieldIDFromTypeAndBase(itemTypeID, fieldID) || fieldID,
this.itemTypeID
);
if (!isValidForType[field]) {
Zotero.logError("Discarding unknown JSON field " + field + " for item " + this.libraryKey);
Zotero.logError("Discarding invalid field " + field + " for type " + itemTypeID
+ " for item " + this.libraryKey);
continue;
}
this.setField(field, json[field]);

View file

@ -966,6 +966,17 @@ describe("Zotero.Item", function () {
})
describe("#fromJSON()", function () {
it("should ignore unknown fields", function* () {
var json = {
itemType: "journalArticle",
title: "Test",
foo: "Invalid"
};
var item = new Zotero.Item;
item.fromJSON(json);
assert.equal(item.getField('title'), 'Test');
})
it("should accept ISO 8601 dates", function* () {
var json = {
itemType: "journalArticle",