Skip to content

Commit

Permalink
ensure we don't crash on a zero field notetype
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed Aug 23, 2020
1 parent fa46ef9 commit 4df89c7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rslib/src/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)));
}

Expand Down

0 comments on commit 4df89c7

Please sign in to comment.