From aedf88ee6dea0a4a7f3b9978f4cb5c3cc8e3f231 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 6 May 2012 18:08:15 +0900 Subject: [PATCH] don't allow {{c0:: --- anki/models.py | 2 ++ tests/test_models.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/anki/models.py b/anki/models.py index 034a9f01f..0b5d159b1 100644 --- a/anki/models.py +++ b/anki/models.py @@ -533,6 +533,8 @@ select id from notes where mid = ?)""" % " ".join(map), ord = map[fname][0] ords.update([int(m)-1 for m in re.findall( "{{c(\d+)::[^}]*?}}", sflds[ord])]) + if -1 in ords: + ords.remove(-1) return list(ords) # Sync handling diff --git a/tests/test_models.py b/tests/test_models.py index 01e69c13d..fde8644c7 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -157,6 +157,10 @@ def test_cloze(): f['Text'] = "{{c2::hello}} {{c1::foo}}" f.flush() assert d.cardCount() == cnt + 1 + # 0 or negative indices are not supported + f['Text'] += "{{c0::zero}} {{c-1:foo}}" + f.flush() + assert len(f.cards()) == 2 def test_modelChange(): deck = getEmptyDeck()