Fix #5140: Unexpected error: PublicSuffix::DomainInvalid for searching some newgrounds urls in /artists

When the artist name couldn't found for a Newgrounds URL, for example
for `https://www.newgrounds.com/dump/item`, then the `profile_url`
method erroneously returned `https://.newgrounds.com`. This led to an
error later on when the artist finder tried to parse the invalid URL.

Also fix `strategy_should_work` to test that the profile URL is a valid
URL, and not to try to download the file when image_urls is empty.
This commit is contained in:
evazion
2022-04-22 23:05:47 -05:00
parent db6bb2ccac
commit 76d9e86724
4 changed files with 22 additions and 2 deletions

View File

@@ -20,7 +20,7 @@ module SourceTestHelper
assert_not(strategy.image_urls.include?(nil))
end
should_download_successfully(strategy, download_size) unless deleted
should_download_successfully(strategy, download_size) unless deleted || strategy.image_urls.empty?
# {profile_url: nil}[:profile_url].present? -> false
# Doing it this way instead we can check profile_url even if it's passed as a nil.
@@ -49,6 +49,7 @@ module SourceTestHelper
def should_handle_artists_correctly(strategy, profile_url)
if profile_url.present?
should "correctly match a strategy to an artist with the same profile url" do
assert_not_nil(Danbooru::URL.parse(strategy.profile_url))
assert_equal(profile_url, strategy.profile_url)
artist = FactoryBot.create(:artist, name: strategy.artist_name, url_string: profile_url)
assert_equal([artist], strategy.artists)