From a65f241258bec1cc6ad9643c701d178c0659ac8b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 29 Apr 2011 11:46:26 +0900 Subject: [PATCH] gracefully handle invalid queries --- anki/find.py | 5 ++++- tests/test_find.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/anki/find.py b/anki/find.py index fe8afcd8e..3891e2f6f 100644 --- a/anki/find.py +++ b/anki/find.py @@ -157,7 +157,10 @@ order by %s""" % (lim, sort) cond = "c.id in (select id from cards order by mod desc limit 100)" if neg: cond = "not (%s)" % cond - self.lims['card'].append(cond) + if cond: + self.lims['card'].append(cond) + else: + self.lims['valid'] = False def _findText(self, val, neg, c): val = val.replace("*", "%") diff --git a/tests/test_find.py b/tests/test_find.py index 0434b5985..7e0f8fb87 100644 --- a/tests/test_find.py +++ b/tests/test_find.py @@ -110,6 +110,8 @@ def test_findCards(): assert len(deck.findCards("helloworld", full=True)) == 1 assert len(deck.findCards("front:helloworld")) == 0 assert len(deck.findCards("front:helloworld", full=True)) == 1 + # searching for an invalid special tag should not error + assert len(deck.findCards("is:invalid")) == 0 def test_findReplace(): deck = getEmptyDeck()