From 4838726b871043b4574e4d18a85a185a9ca3b9a8 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 9 Sep 2020 18:00:53 -0400 Subject: [PATCH] Throw invalid-data error on unknown attachment link mode in fromJSON() --- chrome/content/zotero/xpcom/data/item.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 9b62b6d1b4..9456e1e064 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -2707,7 +2707,7 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentLinkMode', { break; default: - throw ("Invalid attachment link mode '" + val + throw new Error("Invalid attachment link mode '" + val + "' in Zotero.Item.attachmentLinkMode setter"); } @@ -4310,7 +4310,13 @@ Zotero.Item.prototype.fromJSON = function (json, options = {}) { // Attachment metadata // 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; case 'contentType':