From 07237bc2bc5dcc013850ce6c7deed9a940c6d239 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 14 Aug 2016 09:37:29 +0200 Subject: [PATCH] server/tags: fix changing name case --- server/szurubooru/func/tags.py | 14 +++++++------- server/szurubooru/tests/api/test_tag_updating.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/server/szurubooru/func/tags.py b/server/szurubooru/func/tags.py index 0bda2522..c8f7aa3c 100644 --- a/server/szurubooru/func/tags.py +++ b/server/szurubooru/func/tags.py @@ -27,6 +27,9 @@ def _lower_list(names): def _check_name_intersection(names1, names2): return len(set(_lower_list(names1)).intersection(_lower_list(names2))) > 0 +def _check_name_intersection_case_sensitive(names1, names2): + return len(set(names1).intersection(names2)) > 0 + def sort_tags(tags): default_category = tag_categories.try_get_default_category() default_category_name = default_category.name if default_category else None @@ -222,14 +225,11 @@ def update_tag_names(tag, names): if len(existing_tags): raise TagAlreadyExistsError( 'One of names is already used by another tag.') - tag_names_to_remove = [] - for tag_name in tag.names: - if not _check_name_intersection([tag_name.name], names): - tag_names_to_remove.append(tag_name) - for tag_name in tag_names_to_remove: - tag.names.remove(tag_name) + for tag_name in tag.names[:]: + if not _check_name_intersection_case_sensitive([tag_name.name], names): + tag.names.remove(tag_name) for name in names: - if not _check_name_intersection(_get_plain_names(tag), [name]): + if not _check_name_intersection_case_sensitive(_get_plain_names(tag), [name]): tag.names.append(db.TagName(name)) def update_tag_implications(tag, relations): diff --git a/server/szurubooru/tests/api/test_tag_updating.py b/server/szurubooru/tests/api/test_tag_updating.py index 3f3365a3..151f62b5 100644 --- a/server/szurubooru/tests/api/test_tag_updating.py +++ b/server/szurubooru/tests/api/test_tag_updating.py @@ -134,12 +134,12 @@ def test_reusing_own_name(test_ctx, dup_name): input={'names': [dup_name, 'tag3'], 'version': 1}, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'tag1') - assert result['names'] == ['tag1', 'tag3'] + assert result['names'] == [dup_name, 'tag3'] assert tags.try_get_tag_by_name('tag2') is None tag1 = tags.get_tag_by_name('tag1') tag2 = tags.get_tag_by_name('tag3') assert tag1.tag_id == tag2.tag_id - assert [name.name for name in tag1.names] == ['tag1', 'tag3'] + assert [name.name for name in tag1.names] == [dup_name, 'tag3'] def test_duplicating_names(test_ctx): db.session.add(