From 6335dcb90e60c25647cbbbe66d69c9d157b27ed4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 19 Feb 2017 12:49:52 +1000 Subject: [PATCH] canonicalize to NFC form on edit/import --- anki/importing/noteimp.py | 5 +++++ aqt/editor.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/anki/importing/noteimp.py b/anki/importing/noteimp.py index 91e84f1f4..ffbf63de4 100644 --- a/anki/importing/noteimp.py +++ b/anki/importing/noteimp.py @@ -3,6 +3,9 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import cgi + +import unicodedata + from anki.consts import NEW_CARDS_RANDOM, STARTING_FACTOR from anki.lang import _ from anki.utils import fieldChecksum, guid64, timestampID, \ @@ -126,6 +129,8 @@ class NoteImporter(Importer): n.fields[c] = n.fields[c].strip() if not self.allowHTML: n.fields[c] = n.fields[c].replace("\n", "
") + n.fields[c] = unicodedata.normalize("NFC", n.fields[c]) + n.tags = [unicodedata.normalize("NFC", t) for t in n.tags] fld0 = n.fields[fld0idx] csum = fieldChecksum(fld0) # first field must exist diff --git a/aqt/editor.py b/aqt/editor.py index 0ebffa3c0..413197f55 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -10,6 +10,7 @@ import warnings import html import mimetypes import base64 +import unicodedata from anki.lang import _ from aqt.qt import * @@ -569,6 +570,7 @@ class Editor: if cmd.startswith("blur") or cmd.startswith("key"): (type, txt) = cmd.split(":", 1) txt = urllib.parse.unquote(txt) + txt = unicodedata.normalize("NFC", txt) txt = self.mungeHTML(txt) # misbehaving apps may include a null byte in the text txt = txt.replace("\x00", "") @@ -763,8 +765,9 @@ class Editor: def saveTags(self): if not self.note: return + tagsTxt = unicodedata.normalize("NFC", self.tags.text()) self.note.tags = self.mw.col.tags.canonify( - self.mw.col.tags.split(self.tags.text())) + self.mw.col.tags.split(tagsTxt)) self.tags.setText(self.mw.col.tags.join(self.note.tags).strip()) if not self.addMode: self.note.flush()