ensure we don't crash on a zero field notetype
This commit is contained in:
parent
fa46ef9e37
commit
4df89c7c26
@ -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
|
||||
)));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user