From 1077c71c2ed2bd0cf9a9e117f1a4692c9aa78bfc Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 8 Apr 2012 21:39:04 +0900 Subject: [PATCH] don't throw error in half-complete field filter --- anki/template/template.py | 3 ++- tests/test_collection.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/anki/template/template.py b/anki/template/template.py index 8a6e9aec0..f3bec9e66 100644 --- a/anki/template/template.py +++ b/anki/template/template.py @@ -186,7 +186,8 @@ class Template(object): return "" else: # hook-based field modifier - txt = runFilter('fmod_' + mod, txt, extra, context, tag, tag_name); + txt = runFilter('fmod_' + mod, txt or '', extra, context, + tag, tag_name); if txt is None: return '{unknown field %s}' % tag_name return txt diff --git a/tests/test_collection.py b/tests/test_collection.py index cb175ee4f..7e610dd8c 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -147,6 +147,7 @@ def test_furigana(): deck = getEmptyDeck() mm = deck.models m = mm.current() + # filter should work m['tmpls'][0]['qfmt'] = '{{kana:Front}}' mm.save(m) n = deck.newNote() @@ -154,6 +155,11 @@ def test_furigana(): deck.addNote(n) c = n.cards()[0] assert c.q().endswith("abc") + # and should avoid sound n['Front'] = 'foo[sound:abc.mp3]' n.flush() assert "sound:" in c.q(reload=True) + # it shouldn't throw an error while people are editing + m['tmpls'][0]['qfmt'] = '{{kana:}}' + mm.save(m) + c.q(reload=True)