From d235ce223fc9c35621d7ce1d9a810b9268f5f160 Mon Sep 17 00:00:00 2001 From: Sindrake Date: Sat, 20 Jul 2024 16:07:55 -0700 Subject: [PATCH] [Tags] Make tag preview case insensitive --- .rubocop_todo.yml | 8 -------- app/logical/tag_query.rb | 2 +- app/logical/tags_preview.rb | 12 ++++++------ 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a6ca7b053..cd5334e3f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -344,7 +344,6 @@ Layout/SpaceAfterComma: - 'app/indexes/post_index.rb' - 'app/logical/storage_manager.rb' - 'app/logical/storage_manager/local.rb' - - 'app/logical/tags_preview.rb' - 'app/presenters/post_presenter.rb' - 'app/serializers/post_serializer.rb' - 'app/views/admin/danger_zone/index.html.erb' @@ -403,7 +402,6 @@ Layout/SpaceAroundOperators: Layout/SpaceBeforeBlockBraces: Exclude: - 'app/controllers/posts_controller.rb' - - 'app/logical/tags_preview.rb' - 'app/models/post.rb' - 'app/models/tag_relationship.rb' - 'app/models/user.rb' @@ -459,7 +457,6 @@ Layout/SpaceInsideBlockBraces: - 'app/logical/post_sets/base.rb' - 'app/logical/related_tag_calculator.rb' - 'app/logical/sources/alternates.rb' - - 'app/logical/tags_preview.rb' - 'app/models/artist.rb' - 'app/models/bulk_update_request.rb' - 'app/models/favorite.rb' @@ -531,7 +528,6 @@ Layout/SpaceInsideHashLiteralBraces: - 'app/logical/session_creator.rb' - 'app/logical/session_loader.rb' - 'app/logical/sources/strategies/pixiv_slim.rb' - - 'app/logical/tags_preview.rb' - 'app/logical/user_deletion.rb' - 'app/models/ban.rb' - 'app/models/bulk_update_request.rb' @@ -1166,7 +1162,6 @@ Rails/CompactBlank: Exclude: - 'app/controllers/posts_controller.rb' - 'app/logical/bulk_update_request_importer.rb' - - 'app/logical/tags_preview.rb' - 'app/models/post_replacement.rb' - 'app/models/tag_alias.rb' @@ -1311,7 +1306,6 @@ Rails/OutputSafety: # This cop supports unsafe autocorrection (--autocorrect-all). Rails/Pluck: Exclude: - - 'app/logical/tags_preview.rb' - 'app/models/post.rb' - 'test/functional/forum_topics_controller_test.rb' - 'test/functional/post_events_controller_test.rb' @@ -2462,7 +2456,6 @@ Style/StringLiterals: - 'app/logical/session_loader.rb' - 'app/logical/storage_manager.rb' - 'app/logical/storage_manager/local.rb' - - 'app/logical/tags_preview.rb' - 'app/logical/upload_service/replacer.rb' - 'app/logical/user_deletion.rb' - 'app/logical/user_email_change.rb' @@ -2653,7 +2646,6 @@ Style/SymbolProc: - 'app/controllers/posts_controller.rb' - 'app/logical/post_sets/base.rb' - 'app/logical/post_sets/post.rb' - - 'app/logical/tags_preview.rb' - 'app/models/artist_url.rb' - 'app/models/post.rb' - 'app/models/user.rb' diff --git a/app/logical/tag_query.rb b/app/logical/tag_query.rb index 6d74647f2..7ca55eea5 100644 --- a/app/logical/tag_query.rb +++ b/app/logical/tag_query.rb @@ -69,7 +69,7 @@ class TagQuery end def self.scan(query) - tagstr = query.to_s.downcase.unicode_normalize(:nfc).strip + tagstr = query.to_s.unicode_normalize(:nfc).strip quote_delimited = [] tagstr = tagstr.gsub(/[-~]?\w*?:".*?"/) do |match| quote_delimited << match diff --git a/app/logical/tags_preview.rb b/app/logical/tags_preview.rb index 915aa8cbb..92ed56b7b 100644 --- a/app/logical/tags_preview.rb +++ b/app/logical/tags_preview.rb @@ -2,18 +2,18 @@ class TagsPreview def initialize(tags: nil) - @tags = TagQuery.scan(tags).map {|x| {a: x, type: 'tag'}} + @tags = TagQuery.scan(tags).map { |x| { a: x.downcase, type: "tag" } } aliases implications tag_types end def aliases - names = @tags.map{ |tag| tag[:a] }.reject {|y| y.blank?} - aliased = TagAlias.to_aliased_with_originals(names).reject {|k,v| k == v } + names = @tags.pluck(:a).compact_blank + aliased = TagAlias.to_aliased_with_originals(names).reject { |k, v| k == v } @tags.map! do |tag| if aliased[tag[:a]] - {a: tag[:a], b: aliased[tag[:a]], type: 'alias'} + { a: tag[:a], b: aliased[tag[:a]], type: "alias" } else tag end @@ -21,10 +21,10 @@ class TagsPreview end def implications - names = @tags.map {|tag| tag[:b] || tag[:a] } + names = @tags.map { |tag| tag[:b] || tag[:a] } implications = TagImplication.descendants_with_originals(names) implications.each do |implication, descendants| - @tags += descendants.map { |descendant| {a: implication, b: descendant, type: 'implication'} } + @tags += descendants.map { |descendant| { a: implication, b: descendant, type: "implication" } } end end