commit 8933e3b5866d4aefcf17729c7d44bf33de75989b
parent 84a6ea18f6d70df847c8a13224e0a25e63c9b0d1
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 22 Dec 2015 01:49:45 -0500
Item.toJSON() should output unset mtime/md5 as null, not undefined
Diffstat:
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
@@ -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
@@ -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 () {