normalize first field before comparing with local DB

https://forums.ankiweb.net/t/python-checksum-rust-checksum/8195/8
This commit is contained in:
Damien Elmes 2021-03-17 22:22:58 +10:00
parent 8c1a386202
commit e356139d8c

View file

@ -2,6 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import html import html
import unicodedata
from typing import Dict, List, Optional, Tuple, Union from typing import Dict, List, Optional, Tuple, Union
from anki.collection import Collection from anki.collection import Collection
@ -147,14 +148,14 @@ class NoteImporter(Importer):
n.fields[c] = n.fields[c].strip() n.fields[c] = n.fields[c].strip()
if not self.allowHTML: if not self.allowHTML:
n.fields[c] = n.fields[c].replace("\n", "<br>") n.fields[c] = n.fields[c].replace("\n", "<br>")
fld0 = n.fields[fld0idx] fld0 = unicodedata.normalize("NFC", n.fields[fld0idx])
csum = fieldChecksum(fld0)
# first field must exist # first field must exist
if not fld0: if not fld0:
self.log.append( self.log.append(
self.col.tr(TR.IMPORTING_EMPTY_FIRST_FIELD, val=" ".join(n.fields)) self.col.tr(TR.IMPORTING_EMPTY_FIRST_FIELD, val=" ".join(n.fields))
) )
continue continue
csum = fieldChecksum(fld0)
# earlier in import? # earlier in import?
if fld0 in firsts and self.importMode != ADD_MODE: if fld0 in firsts and self.importMode != ADD_MODE:
# duplicates in source file; log and ignore # duplicates in source file; log and ignore