www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 6c58389563607fea62b9b8fdc6d207c47f60e628
parent a35d903e77c7332779e1106e4b02acdd7a62d68e
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon, 27 Feb 2017 23:34:16 -0500

Fix translation error when firstName is null for fieldMode 1

Some translators (e.g., CrossRef) return firstName: null with fieldMode:
1, which was causing an error

Diffstat:
Mchrome/content/zotero/xpcom/data/creators.js | 7++++---
Mtest/tests/creatorsTest.js | 13+++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/creators.js b/chrome/content/zotero/xpcom/data/creators.js @@ -165,13 +165,14 @@ Zotero.Creators = new function() { if (data.name !== undefined && data.fieldMode === 0) { throw new Error("'fieldMode' cannot be 0 with 'name' property"); } - if (data.fieldMode === 1 && !(data.firstName === undefined || data.firstName === "")) { + if (data.fieldMode === 1 + && !(data.firstName === undefined || data.firstName === "" || data.firstName === null)) { throw new Error("'fieldMode' cannot be 1 with 'firstName' property"); } if (data.name !== undefined && typeof data.name != 'string') { throw new Error("'name' must be a string"); } - if (data.firstName !== undefined && typeof data.firstName != 'string') { + if (data.firstName !== undefined && data.firstName !== null && typeof data.firstName != 'string') { throw new Error("'firstName' must be a string"); } if (data.lastName !== undefined && typeof data.lastName != 'string') { @@ -189,7 +190,7 @@ Zotero.Creators = new function() { switch (field) { case 'firstName': case 'lastName': - if (val === undefined) continue; + if (val === undefined || val === null) continue; cleanedData[field] = val.trim().normalize(); break; diff --git a/test/tests/creatorsTest.js b/test/tests/creatorsTest.js @@ -18,4 +18,17 @@ describe("Zotero.Creators", function() { assert.propertyVal(data2, "lastName", data1.lastName); }); }); + + describe("#cleanData()", function () { + it("should allow firstName to be null for fieldMode 1", function* () { + var data = Zotero.Creators.cleanData({ + firstName: null, + lastName: "Test", + fieldMode: 1 + }); + assert.propertyVal(data, 'fieldMode', 1); + assert.propertyVal(data, 'firstName', ''); + assert.propertyVal(data, 'lastName', 'Test'); + }); + }); });