commit bb0fa7389971ba7f979809ba7971d48a01edf0ac
parent 07ea9dae849fbae9415aa12d6b7694d40f1f629c
Author: Dan Stillman <dstillman@zotero.org>
Date: Sat, 18 Feb 2017 14:19:30 -0500
Fix old-style 'collection' condition for My Library in saved searches
Diffstat:
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js
@@ -1153,6 +1153,9 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
// Old-style library-key hash
if (objKey.indexOf('_') != -1) {
[objLibraryID, objKey] = objKey.split('_');
+ if (objLibraryID === "0") {
+ objLibraryID = Zotero.Libraries.userLibraryID;
+ }
}
// libraryID assigned on search
else if (this.libraryID !== null) {
diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js
@@ -135,6 +135,17 @@ describe("Zotero.Search", function() {
assert.sameMembers(matches, [item.id]);
});
+ it("should find item in collection in old-style format", function* () {
+ var col = yield createDataObject('collection');
+ var item = yield createDataObject('item', { collections: [col.id] });
+
+ var s = new Zotero.Search();
+ s.libraryID = item.libraryID;
+ s.addCondition('collection', 'is', "0_" + col.key);
+ var matches = yield s.search();
+ assert.sameMembers(matches, [item.id]);
+ });
+
it("should find items not in collection", function* () {
var col = yield createDataObject('collection');
var item = yield createDataObject('item', { collections: [col.id] });
@@ -169,6 +180,20 @@ describe("Zotero.Search", function() {
var matches = yield s.search();
assert.sameMembers(matches, [item.id]);
});
+
+ it("should find item in subcollection in recursive mode with old-style key", function* () {
+ var col1 = yield createDataObject('collection');
+ var col2 = yield createDataObject('collection', { parentID: col1.id });
+ var item = yield createDataObject('item', { collections: [col2.id] });
+
+ var s = new Zotero.Search();
+ s.libraryID = item.libraryID;
+ s.addCondition('collection', 'is', "0_" + col1.key);
+ s.addCondition('recursive', 'true');
+ var matches = yield s.search();
+ assert.sameMembers(matches, [item.id]);
+ });
+
});
describe("fileTypeID", function () {