commit dbeecb9b0a15d17ffda1065521e2442d2827a787
parent 746171ab7844e66eed1f3e1f81addd8ab7832a35
Author: Adomas VenĨkauskas <adomas.ven@gmail.com>
Date: Sun, 7 May 2017 17:05:08 +0300
Make itemFromCSLJSON independent of Zotero.Item existance.
Addresses !zotero/zotero-connectors#121"
Diffstat:
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js
@@ -1815,7 +1815,7 @@ Zotero.Utilities = {
* @param {Object} cslItem
*/
"itemFromCSLJSON":function(item, cslItem) {
- var isZoteroItem = item instanceof Zotero.Item,
+ var isZoteroItem = !!item.setType,
zoteroType;
// Some special cases to help us map item types correctly
diff --git a/test/tests/utilitiesTest.js b/test/tests/utilitiesTest.js
@@ -384,6 +384,19 @@ describe("Zotero.Utilities", function() {
assert.equal(item.getField('title'), jsonAttachment.title, 'title imported correctly');
});
+ // For Zotero.Item created in translation sandbox in connectors
+ it("should not depend on Zotero.Item existing", function* () {
+ let item = new Zotero.Item;
+ var Item = Zotero.Item;
+ delete Zotero.Item;
+ assert.throws(() => "" instanceof Zotero.Item);
+
+ let data = loadSampleData('citeProcJSExport');
+ assert.doesNotThrow(Zotero.Utilities.itemFromCSLJSON.bind(Zotero.Utilities, item, Object.values(data)[0]));
+
+ Zotero.Item = Item;
+ assert.doesNotThrow(() => "" instanceof Zotero.Item);
+ })
});
describe("#ellipsize()", function () {