From 76081ab05f257cd53a7b70bf98178826681f9b22 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 11 Feb 2020 00:22:00 -0500 Subject: [PATCH] Fix crash when search uses no-op condition and includeParentsAndChildren E.g., a nonexistent saved search --- chrome/content/zotero/xpcom/data/search.js | 8 ++++++++ test/tests/searchTest.js | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index 3faa42ecaf..e9cf0c8142 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -1605,11 +1605,19 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { } if (includeParentsAndChildren || includeParents) { + // Tweak forceNoResults expression to work with UNION + if (condSQL == '0=1') { + condSQL = 'SELECT 0=1'; + } condSQL += " UNION " + parentSQL; condSQLParams = condSQLParams.concat(parentSQLParams); } if (includeParentsAndChildren || includeChildren) { + // Tweak forceNoResults expression to work with UNION + if (condSQL == '0=1') { + condSQL = 'SELECT 0=1'; + } condSQL += " UNION " + childrenSQL; condSQLParams = condSQLParams.concat(childSQLParams); } diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js index 6ad17cc72e..b77ad92a3e 100644 --- a/test/tests/searchTest.js +++ b/test/tests/searchTest.js @@ -409,6 +409,19 @@ describe("Zotero.Search", function() { }); }); + describe("includeParentsAndChildren", function () { + it("should handle ANY search with no-op condition", async function () { + var s = new Zotero.Search(); + s.libraryID = userLibraryID; + s.name = "Test"; + s.addCondition('joinMode', 'any'); + s.addCondition('savedSearch', 'is', Zotero.Utilities.randomString()); + s.addCondition('includeParentsAndChildren', 'true'); + var matches = await s.search(); + assert.lengthOf(matches, 0); + }); + }); + describe("key", function () { it("should allow more than max bound parameters", function* () { let s = new Zotero.Search();