ensure we don't crash on a zero field notetype

This commit is contained in:
Damien Elmes 2020-08-23 12:09:36 +10:00
parent fa46ef9e37
commit 4df89c7c26

View File

@ -79,11 +79,12 @@ impl Note {
/// Prepare note for saving to the database. Does not mark it as modified.
pub fn prepare_for_update(&mut self, nt: &NoteType, normalize_text: bool) -> Result<()> {
assert!(nt.id == self.ntid);
if nt.fields.len() != self.fields.len() {
let notetype_field_count = nt.fields.len().max(1);
if notetype_field_count != self.fields.len() {
return Err(AnkiError::invalid_input(format!(
"note has {} fields, expected {}",
self.fields.len(),
nt.fields.len()
notetype_field_count
)));
}