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
This commit is contained in:
parent
a35d903e77
commit
6c58389563
2 changed files with 17 additions and 3 deletions
|
@ -165,13 +165,14 @@ Zotero.Creators = new function() {
|
||||||
if (data.name !== undefined && data.fieldMode === 0) {
|
if (data.name !== undefined && data.fieldMode === 0) {
|
||||||
throw new Error("'fieldMode' cannot be 0 with 'name' property");
|
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");
|
throw new Error("'fieldMode' cannot be 1 with 'firstName' property");
|
||||||
}
|
}
|
||||||
if (data.name !== undefined && typeof data.name != 'string') {
|
if (data.name !== undefined && typeof data.name != 'string') {
|
||||||
throw new Error("'name' must be a 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");
|
throw new Error("'firstName' must be a string");
|
||||||
}
|
}
|
||||||
if (data.lastName !== undefined && typeof data.lastName != 'string') {
|
if (data.lastName !== undefined && typeof data.lastName != 'string') {
|
||||||
|
@ -189,7 +190,7 @@ Zotero.Creators = new function() {
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case 'firstName':
|
case 'firstName':
|
||||||
case 'lastName':
|
case 'lastName':
|
||||||
if (val === undefined) continue;
|
if (val === undefined || val === null) continue;
|
||||||
cleanedData[field] = val.trim().normalize();
|
cleanedData[field] = val.trim().normalize();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -18,4 +18,17 @@ describe("Zotero.Creators", function() {
|
||||||
assert.propertyVal(data2, "lastName", data1.lastName);
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue