diff --git a/rslib/src/notes.rs b/rslib/src/notes.rs index 6021cb3e5..23e9f7019 100644 --- a/rslib/src/notes.rs +++ b/rslib/src/notes.rs @@ -24,8 +24,6 @@ use std::{ define_newtype!(NoteID, i64); -// fixme: ensure nulls and x1f not in field contents - #[derive(Default)] pub(crate) struct TransformNoteOutput { pub changed: bool, @@ -88,6 +86,12 @@ impl Note { ))); } + for field in &mut self.fields { + if field.contains(invalid_char_for_field) { + *field = field.replace(invalid_char_for_field, ""); + } + } + if normalize_text { for field in &mut self.fields { ensure_string_in_nfc(field); @@ -226,6 +230,10 @@ fn anki_base91(mut n: u64) -> String { buf.chars().rev().collect() } +fn invalid_char_for_field(c: char) -> bool { + c.is_ascii_control() && c != '\n' && c != '\t' +} + impl Collection { fn canonify_note_tags(&self, note: &mut Note, usn: Usn) -> Result<()> { if !note.tags.is_empty() {