From 8933e3b5866d4aefcf17729c7d44bf33de75989b Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 22 Dec 2015 01:49:45 -0500 Subject: [PATCH] Item.toJSON() should output unset mtime/md5 as null, not undefined --- chrome/content/zotero/xpcom/data/item.js | 4 ++-- test/tests/itemTest.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index d7e940257b..27a74b9097 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -3905,8 +3905,8 @@ Zotero.Item.prototype.toJSON = Zotero.Promise.coroutine(function* (options = {}) } if (this.isFileAttachment()) { - obj.md5 = yield this.attachmentHash; - obj.mtime = yield this.attachmentModificationTime; + obj.mtime = (yield this.attachmentModificationTime) || null; + obj.md5 = (yield this.attachmentHash) || null; } } diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index ae69311b08..e83ef7332a 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -873,6 +873,18 @@ describe("Zotero.Item", function () { assert.strictEqual(json.deleted, 1); }) + + it("should output unset storage properties as null", function* () { + var item = new Zotero.Item('attachment'); + item.attachmentLinkMode = 'imported_file'; + item.fileName = 'test.txt'; + var id = yield item.saveTx(); + var json = yield item.toJSON(); + + Zotero.debug(json); + assert.isNull(json.mtime); + assert.isNull(json.md5); + }) }) describe("'full' mode", function () {