normalize field before checking duplicates

https://forums.ankiweb.net/t/unicode-normalisation/2531
This commit is contained in:
Damien Elmes 2020-08-23 12:09:55 +10:00
parent 4df89c7c26
commit 63b8b32602

View File

@ -10,7 +10,7 @@ use crate::{
err::{AnkiError, Result}, err::{AnkiError, Result},
notetype::{CardGenContext, NoteField, NoteType, NoteTypeID}, notetype::{CardGenContext, NoteField, NoteType, NoteTypeID},
template::field_is_empty, template::field_is_empty,
text::{ensure_string_in_nfc, strip_html_preserving_image_filenames}, text::{ensure_string_in_nfc, normalize_to_nfc, strip_html_preserving_image_filenames},
timestamp::TimestampSecs, timestamp::TimestampSecs,
types::Usn, types::Usn,
}; };
@ -424,7 +424,12 @@ impl Collection {
pub(crate) fn note_is_duplicate_or_empty(&self, note: &Note) -> Result<DuplicateState> { pub(crate) fn note_is_duplicate_or_empty(&self, note: &Note) -> Result<DuplicateState> {
if let Some(field1) = note.fields.get(0) { if let Some(field1) = note.fields.get(0) {
let stripped = strip_html_preserving_image_filenames(field1); let field1 = if self.normalize_note_text() {
normalize_to_nfc(field1)
} else {
field1.into()
};
let stripped = strip_html_preserving_image_filenames(&field1);
if stripped.trim().is_empty() { if stripped.trim().is_empty() {
Ok(DuplicateState::Empty) Ok(DuplicateState::Empty)
} else { } else {