Throw invalid-data error on unknown attachment link mode in fromJSON()

This commit is contained in:
Dan Stillman 2020-09-09 18:00:53 -04:00
parent e9473caa14
commit 4838726b87

View file

@ -2707,7 +2707,7 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentLinkMode', {
break; break;
default: default:
throw ("Invalid attachment link mode '" + val throw new Error("Invalid attachment link mode '" + val
+ "' in Zotero.Item.attachmentLinkMode setter"); + "' in Zotero.Item.attachmentLinkMode setter");
} }
@ -4310,7 +4310,13 @@ Zotero.Item.prototype.fromJSON = function (json, options = {}) {
// Attachment metadata // Attachment metadata
// //
case 'linkMode': case 'linkMode':
this.attachmentLinkMode = Zotero.Attachments["LINK_MODE_" + val.toUpperCase()]; let linkMode = Zotero.Attachments["LINK_MODE_" + val.toUpperCase()];
if (linkMode === undefined) {
let e = new Error(`Unknown attachment link mode '${val}'`);
e.name = "ZoteroInvalidDataError";
throw e;
}
this.attachmentLinkMode = linkMode;
break; break;
case 'contentType': case 'contentType':