From 4df89c7c26c596e2e45947ecd2347bf46813a31b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 23 Aug 2020 12:09:36 +1000 Subject: [PATCH] ensure we don't crash on a zero field notetype --- rslib/src/notes.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rslib/src/notes.rs b/rslib/src/notes.rs index 657b0750b..35a56d7a6 100644 --- a/rslib/src/notes.rs +++ b/rslib/src/notes.rs @@ -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 ))); }