From d25e2453a641b1ddb3e7f2211d84ff5490445140 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 26 May 2012 13:00:01 +0900 Subject: [PATCH] catch invalid grouping --- anki/find.py | 6 +++++- tests/test_find.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) 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()