From 30f19c07be9425824120f3faf163de3181ac9d79 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 13 Dec 2018 20:36:04 +1000 Subject: [PATCH] find comparisons needs to be normalized this data should probably be normalized when it's originally added to the collection https://anki.tenderapp.com/discussions/ankidesktop/31409-cant-search-by-deck-when-searching-decks-containing-arabic-text --- anki/decks.py | 4 +++- anki/find.py | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/anki/decks.py b/anki/decks.py index efd109853..29a698806 100644 --- a/anki/decks.py +++ b/anki/decks.py @@ -3,6 +3,8 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import copy, operator +import unicodedata + from anki.utils import intTime, ids2str, json from anki.hooks import runHook from anki.consts import * @@ -130,7 +132,7 @@ class DeckManager: "Add a deck with NAME. Reuse deck if already exists. Return id as int." name = name.replace('"', '') for id, g in list(self.decks.items()): - if g['name'].lower() == name.lower(): + if unicodedata.normalize("NFC", g['name'].lower()) == name.lower(): return int(id) if not create: return None diff --git a/anki/find.py b/anki/find.py index 378565113..6c27c61a8 100644 --- a/anki/find.py +++ b/anki/find.py @@ -4,6 +4,7 @@ import re import sre_constants +import unicodedata from anki.utils import ids2str, splitFields, joinFields, intTime, fieldChecksum, stripHTMLMedia from anki.consts import * @@ -368,7 +369,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """+preds ids = [] val = val.lower() for m in self.col.models.all(): - if m['name'].lower() == val: + if unicodedata.normalize("NFC", m['name'].lower()) == val: ids.append(m['id']) return "n.mid in %s" % ids2str(ids) @@ -396,7 +397,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """+preds ids = set() val = re.escape(val).replace(r"\*", ".*") for d in self.col.decks.all(): - if re.match("(?i)"+val, d['name']): + if re.match("(?i)"+val, unicodedata.normalize("NFC", d['name'])): ids.update(dids(d['id'])) if not ids: return @@ -416,7 +417,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """+preds lims = [] for m in self.col.models.all(): for t in m['tmpls']: - if t['name'].lower() == val.lower(): + if unicodedata.normalize("NFC", t['name'].lower()) == val.lower(): if m['type'] == MODEL_CLOZE: # if the user has asked for a cloze card, we want # to give all ordinals, so we just limit to the @@ -434,7 +435,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """+preds mods = {} for m in self.col.models.all(): for f in m['flds']: - if f['name'].lower() == field: + if unicodedata.normalize("NFC", f['name'].lower()) == field: mods[str(m['id'])] = (m, f['ord']) if not mods: # nothing has that field