Allow empty field name in templates

This commit is contained in:
RumovZ 2021-05-28 10:35:07 +02:00
parent c6e78e6f21
commit 33bf391114
2 changed files with 8 additions and 6 deletions

View file

@ -143,6 +143,10 @@ def test_furigana():
n["Front"] = "foo[sound:abc.mp3]"
n.flush()
assert "anki:play" 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)
def test_translate():

View file

@ -338,12 +338,10 @@ impl Notetype {
"Type",
];
names.into_iter().any(|name| {
!special_fields.contains(&name.as_ref())
&& self
.fields
.iter()
.map(|field| &field.name)
.all(|field_name| field_name != name.as_ref())
// The empty field name is allowed as it may be used by add-ons.
!name.as_ref().is_empty()
&& !special_fields.contains(&name.as_ref())
&& self.fields.iter().all(|field| field.name != name.as_ref())
})
}