From 302994e5d907ad648b39341b04a1dd4835ae11ab Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 13 Apr 2018 22:39:52 -0500 Subject: [PATCH] Fix #3639: Favorite count pixiv tags aren't skipped by translated tags. --- app/logical/sources/strategies/base.rb | 2 ++ app/logical/sources/strategies/pixiv.rb | 2 +- test/unit/sources/pixiv_test.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/logical/sources/strategies/base.rb b/app/logical/sources/strategies/base.rb index 3ce40e0e5..2f576f667 100644 --- a/app/logical/sources/strategies/base.rb +++ b/app/logical/sources/strategies/base.rb @@ -83,6 +83,8 @@ module Sources # Given a tag from the source site, should return an array of corresponding Danbooru tags. def translate_tag(untranslated_tag) + return [] if untranslated_tag.blank? + translated_tag_names = WikiPage.active.other_names_equal(untranslated_tag).uniq.pluck(:title) translated_tag_names = TagAlias.to_aliased(translated_tag_names) translated_tags = Tag.where(name: translated_tag_names) diff --git a/app/logical/sources/strategies/pixiv.rb b/app/logical/sources/strategies/pixiv.rb index ebf93ea92..a0c521bdd 100644 --- a/app/logical/sources/strategies/pixiv.rb +++ b/app/logical/sources/strategies/pixiv.rb @@ -57,7 +57,7 @@ module Sources end def translate_tag(tag) - normalized_tag = tag.gsub(/\A(\S+?)_?\d+users入り\Z/i, '\1') + normalized_tag = tag.gsub(/\d+users入り\z/i, "") translated_tags = super(normalized_tag) if translated_tags.empty? && normalized_tag.include?("/") diff --git a/test/unit/sources/pixiv_test.rb b/test/unit/sources/pixiv_test.rb index 6c10e5e2d..a2ba1a350 100644 --- a/test/unit/sources/pixiv_test.rb +++ b/test/unit/sources/pixiv_test.rb @@ -228,6 +228,15 @@ module Sources assert_equal([toosaka_rin], @site.translate_tag("遠坂凛")) end + + should "not translate '1000users入り' to '1'" do + FactoryBot.create(:tag, name: "1", post_count: 1) + source = get_source("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=60665428") + tags = %w[Fate/GrandOrder グランブルーファンタジー 手袋 1000users入り] + + assert_equal(tags.sort, source.tags.map(&:first).sort) + assert_equal(["fate/grand_order"], source.translated_tags.map(&:first)) + end end end end