diff --git a/anki/find.py b/anki/find.py index ac1cb1d2a..7126c2c7f 100644 --- a/anki/find.py +++ b/anki/find.py @@ -22,7 +22,11 @@ class Finder(object): return [] order, rev = self._order(order) sql = self._query(preds, order) - res = self.col.db.list(sql, *args) + try: + res = self.col.db.list(sql, *args) + except: + # invalid grouping + return [] if rev: res.reverse() return res diff --git a/tests/test_find.py b/tests/test_find.py index 4d56f9207..979c47dfe 100644 --- a/tests/test_find.py +++ b/tests/test_find.py @@ -204,6 +204,9 @@ def test_findCards(): assert len(deck.findCards("-(tag:monkey OR tag:sheep)")) == 6 assert len(deck.findCards("tag:monkey or (tag:sheep sheep)")) == 2 assert len(deck.findCards("tag:monkey or (tag:sheep octopus)")) == 1 + # invalid grouping shouldn't error + assert len(deck.findCards(")")) == 0 + assert len(deck.findCards("(()")) == 0 def test_findReplace(): deck = getEmptyDeck()