don't throw error in half-complete field filter

This commit is contained in:
Damien Elmes 2012-04-08 21:39:04 +09:00
parent 71645aacb5
commit 1077c71c2e
2 changed files with 8 additions and 1 deletions

View file

@ -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

View file

@ -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)