From b1e361bb328da522dc6ae4efebedf9ef36f583c6 Mon Sep 17 00:00:00 2001 From: "Soren I. Bjornstad" Date: Sun, 27 Jul 2014 17:55:11 -0500 Subject: [PATCH] don't allow tags of different cases Previously they were allowed to be added, but all searches and operations treated them as case-sensitive, creating an inconsistency. The new implementation will change new tags with different case than existing ones to the version currently in the database. This may cause some slowdown in collections with a very large number of tags since the only way to do this at the moment is to scan through every one of them. Changing the format tags are stored in in the future may be useful. --- anki/tags.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/anki/tags.py b/anki/tags.py index 0ab99cbf4..aff74082e 100644 --- a/anki/tags.py +++ b/anki/tags.py @@ -37,8 +37,6 @@ class TagManager(object): def register(self, tags, usn=None): "Given a list of tags, add any missing ones to tag registry." - # case is stored as received, so user can create different case - # versions of the same tag if they ignore the qt autocomplete. found = False for t in tags: if t not in self.tags: @@ -145,8 +143,14 @@ class TagManager(object): ########################################################################## def canonify(self, tagList): - "Strip duplicates and sort." - strippedTags = [re.sub("[\"']", "", x) for x in tagList] + "Strip duplicates, adjust case to match existing tags, and sort." + strippedTags = [] + for t in tagList: + s = re.sub("[\"']", "", t) + for existingTag in self.tags: + if s.lower() == existingTag.lower(): + s = existingTag + strippedTags.append(s) return sorted(set(strippedTags)) def inList(self, tag, tags):