Fix search error on nonexistent collection in recursive mode
And don't return results for a nonexistent parent search
This commit is contained in:
parent
6137aeddb8
commit
223f582aa7
2 changed files with 37 additions and 13 deletions
|
@ -1171,6 +1171,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
|
||||||
let objKey = condition.value;
|
let objKey = condition.value;
|
||||||
let objectType = condition.name == 'collection' ? 'collection' : 'search';
|
let objectType = condition.name == 'collection' ? 'collection' : 'search';
|
||||||
let objectTypeClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(objectType);
|
let objectTypeClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(objectType);
|
||||||
|
let forceNoResults = false;
|
||||||
|
|
||||||
// libraryID assigned on search
|
// libraryID assigned on search
|
||||||
if (this.libraryID !== null) {
|
if (this.libraryID !== null) {
|
||||||
|
@ -1202,24 +1203,24 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
|
||||||
objLibraryID, objKey
|
objLibraryID, objKey
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!obj) {
|
if (obj) {
|
||||||
var msg = objectType.charAt(0).toUpperCase() + objectType.substr(1)
|
if (objectType == 'search' && obj == this) {
|
||||||
|
Zotero.warn(`Search "${this.name}" references itself -- skipping condition`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let msg = objectType.charAt(0).toUpperCase() + objectType.substr(1)
|
||||||
+ " " + objKey + " specified in search not found";
|
+ " " + objKey + " specified in search not found";
|
||||||
Zotero.debug(msg, 2);
|
Zotero.debug(msg, 2);
|
||||||
Zotero.log(msg, 'warning', 'chrome://zotero/content/xpcom/search.js');
|
Zotero.log(msg, 'warning', 'chrome://zotero/content/xpcom/search.js');
|
||||||
if (objectType == 'search') {
|
forceNoResults = true;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
obj = {
|
|
||||||
id: 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (objectType == 'search' && obj == this) {
|
|
||||||
Zotero.warn(`Search "${this.name}" references itself -- skipping condition`);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectType == 'collection') {
|
if (forceNoResults) {
|
||||||
|
condSQL += '0=1';
|
||||||
|
}
|
||||||
|
else if (objectType == 'collection') {
|
||||||
let ids = [obj.id];
|
let ids = [obj.id];
|
||||||
|
|
||||||
// Search descendent collections if recursive search
|
// Search descendent collections if recursive search
|
||||||
|
|
|
@ -193,6 +193,18 @@ describe("Zotero.Search", function() {
|
||||||
var matches = yield s.search();
|
var matches = yield s.search();
|
||||||
assert.sameMembers(matches, [item.id]);
|
assert.sameMembers(matches, [item.id]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return no results for a collection that doesn't exist in recursive mode", async function () {
|
||||||
|
var item = await createDataObject('item');
|
||||||
|
|
||||||
|
var s = new Zotero.Search();
|
||||||
|
s.libraryID = item.libraryID;
|
||||||
|
s.name = "Test";
|
||||||
|
s.addCondition('collection', 'is', Zotero.DataObjectUtilities.generateKey());
|
||||||
|
s.addCondition('recursive', 'true');
|
||||||
|
var matches = await s.search();
|
||||||
|
assert.lengthOf(matches, 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("fileTypeID", function () {
|
describe("fileTypeID", function () {
|
||||||
|
@ -361,6 +373,17 @@ describe("Zotero.Search", function() {
|
||||||
var matches = yield s.search();
|
var matches = yield s.search();
|
||||||
assert.notInclude(matches, item.id);
|
assert.notInclude(matches, item.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return no results for a search that doesn't exist", async function () {
|
||||||
|
var item = await createDataObject('item');
|
||||||
|
|
||||||
|
var s = new Zotero.Search();
|
||||||
|
s.libraryID = item.libraryID;
|
||||||
|
s.name = "Test";
|
||||||
|
s.addCondition('savedSearch', 'is', Zotero.DataObjectUtilities.generateKey());
|
||||||
|
var matches = await s.search();
|
||||||
|
assert.lengthOf(matches, 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("unfiled", function () {
|
describe("unfiled", function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue