Fix #3738: Artist URL search should be case-insensitive for domains.

This commit is contained in:
evazion
2018-09-05 19:14:24 -05:00
parent c2cf6a5441
commit aee1906761
3 changed files with 11 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ class ArtistUrl < ApplicationRecord
nil
else
url = url.sub(%r!^https://!, "http://")
url = url.sub(%r!^http://([^/]+)!i) { |domain| domain.downcase }
url = url.sub(%r!^http://blog\d+\.fc2!, "http://blog.fc2")
url = url.sub(%r!^http://blog-imgs-\d+\.fc2!, "http://blog.fc2")
url = url.sub(%r!^http://blog-imgs-\d+-\w+\.fc2!, "http://blog.fc2")

View File

@@ -205,6 +205,11 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal(["minko"], Artist.find_all_by_url("http://minko.com/x/test.jpg").map(&:name))
end
should "be case-insensitive to domains when finding matches by url" do
a1 = FactoryBot.create(:artist, name: "bkub", url_string: "http://BKUB.example.com")
assert_artist_found(a1.name, "http://bkub.example.com")
end
should "not find duplicates" do
FactoryBot.create(:artist, :name => "warhol", :url_string => "http://warhol.com/x/a/image.jpg\nhttp://warhol.com/x/b/image.jpg")
assert_equal(["warhol"], Artist.find_all_by_url("http://warhol.com/x/test.jpg").map(&:name))

View File

@@ -35,6 +35,11 @@ class ArtistUrlTest < ActiveSupport::TestCase
assert_equal("http://google.com/", url.normalized_url)
end
should "normalise domains to lowercase" do
url = FactoryBot.create(:artist_url, url: "https://ArtistName.example.com")
assert_equal("http://artistname.example.com/", url.normalized_url)
end
context "normalize twitter profile urls" do
setup do
@url = FactoryBot.create(:artist_url, :url => "https://twitter.com/BLAH")