Don't normalize primary data values in Item.setField()

Just enforce proper data types
This commit is contained in:
Dan Stillman 2020-06-21 02:18:06 -04:00
parent cca5dc0314
commit bb0a1dab13
2 changed files with 21 additions and 13 deletions

View file

@ -615,17 +615,6 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) {
throw new Error(`'${field}' value cannot be undefined`);
}
// Normalize values
if (typeof value == 'number') {
value = "" + value;
}
else if (typeof value == 'string') {
value = value.trim().normalize();
}
if (value === "" || value === null || value === false) {
value = false;
}
//Zotero.debug("Setting field '" + field + "' to '" + value + "' (loadIn: " + (loadIn ? 'true' : 'false') + ") for item " + this.id + " ");
if (!field) {
@ -646,6 +635,9 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) {
switch (field) {
case 'itemTypeID':
if (typeof value != 'number' || value != parseInt(value)) {
throw new Error(`${field} must be a number`);
}
break;
case 'dateAdded':
@ -664,10 +656,15 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) {
break;
case 'version':
value = parseInt(value);
if (typeof value != 'number' || value != parseInt(value)) {
throw new Error(`${field} must be a number`);
}
break;
case 'synced':
if (typeof value != 'boolean') {
throw new Error(`${field} must be a boolean`);
}
value = !!value;
break;
@ -714,6 +711,17 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) {
return true;
}
// Normalize values
if (typeof value == 'number') {
value = "" + value;
}
else if (typeof value == 'string') {
value = value.trim().normalize();
}
if (value === "" || value === null || value === false) {
value = false;
}
if (!loadIn) {
this._requireData('itemData');
}

View file

@ -141,7 +141,7 @@ describe("Zotero.DataObject", function() {
var obj = createUnsavedDataObject(type);
var id = yield obj.saveTx();
obj.synced = 1;
obj.synced = true;
yield obj.saveTx();
if (type == 'item') {