From 40d0751e83017bbaf2c708376d7b0700f980e4bc Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 19 Nov 2017 10:27:38 -0600 Subject: [PATCH] Fix NoStrategyError during artist url normalization (#3382). Fixes a bug from 9a3824a. When an artist entry is saved, `ArtistUrl.normalize` is called on every URL, which calls `Sources::Site.new(url)`. This raised NoStrategyError when an artist entry contained URLs that weren't recognized by any strategy. This also caused `Fetch source data` to fail in certain cases when it attempted to find the artist. --- app/models/artist_url.rb | 4 +++- test/unit/sources/tumblr_test.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/artist_url.rb b/app/models/artist_url.rb index af8886756..7efedd221 100644 --- a/app/models/artist_url.rb +++ b/app/models/artist_url.rb @@ -18,7 +18,7 @@ class ArtistUrl < ApplicationRecord url = url.sub(%r!^http://pictures.hentai-foundry.com//!, "http://pictures.hentai-foundry.com/") begin url = Sources::Site.new(url).normalize_for_artist_finder! - rescue PixivApiClient::Error + rescue PixivApiClient::Error, Sources::Site::NoStrategyError end url = url.gsub(/\/+\Z/, "") url + "/" @@ -75,6 +75,8 @@ class ArtistUrl < ApplicationRecord if !Sources::Site.new(normalized_url).normalized_for_artist_finder? self.normalized_url = self.class.normalize(url) end + rescue Sources::Site::NoStrategyError + self.normalized_url = self.class.normalize(url) end def initialize_normalized_url diff --git a/test/unit/sources/tumblr_test.rb b/test/unit/sources/tumblr_test.rb index 83bde93af..b1583301a 100644 --- a/test/unit/sources/tumblr_test.rb +++ b/test/unit/sources/tumblr_test.rb @@ -65,6 +65,14 @@ module Sources should "get the image url" do assert_equal("http://data.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_raw.png", @site.image_url) end + + should "get the artist" do + CurrentUser.user = FactoryGirl.create(:user) + CurrentUser.ip_addr = "127.0.0.1" + + @artist = FactoryGirl.create(:artist, name: "noizave", url_string: "https://noizave.tumblr.com/") + assert_equal([@artist], @site.artists) + end end context "The source for a 'http://*.tumblr.com/image/*' image page" do