diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index 84ab907226..7a26959709 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -75,7 +75,12 @@ Zotero.defineProperty(Zotero.Search.prototype, 'key', { }); Zotero.defineProperty(Zotero.Search.prototype, 'name', { get: function() { return this._get('name'); }, - set: function(val) { return this._set('name', val); } + set: function (val) { + if (!val) { + throw new Error("Saved search name cannot be empty"); + } + return this._set('name', val); + } }); Zotero.defineProperty(Zotero.Search.prototype, 'version', { get: function() { return this._get('version'); }, diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js index da791f1e2b..e6f3891239 100644 --- a/test/tests/searchTest.js +++ b/test/tests/searchTest.js @@ -1,4 +1,11 @@ describe("Zotero.Search", function() { + describe("#name", function () { + it("should fail if empty", async function () { + var s = new Zotero.Search(); + assert.throws(() => s.name = ''); + }); + }); + describe("#addCondition()", function () { it("should convert old-style 'collection' condition value", function* () { var col = yield createDataObject('collection');