artists: normalize urls added to artist entries.

When a URL is added to an artist entry, normalize it to a standard form.

Artist URLs have both a `url` column and a `normalized_url` column. The
`normalized_url` is used for artist finding and the `url` is the raw URL
entered by the user. Previously only the `normalized_url` field was
normalized; now the URL entered by the user is also converted to a
normalized form.

This means that if an URL like this is added to an artist entry:

* http://www.pixiv.net/member.php?id=1234
* http://www.pixiv.net/en/users/1234
* http://www.twitter.com/DanbooruBot/
* http://mobile.twitter.com/DanbooruBot/

It will get normalized to this:

* https://www.pixiv.net/users/1234
* https://twitter.com/DanbooruBot

This fixes problems with duplicate URLs being added to artist entries
because URLs weren't normalized to a single form.
This commit is contained in:
evazion
2022-03-18 01:47:25 -05:00
parent 455ee9a52a
commit 10dac3ee51
5 changed files with 42 additions and 16 deletions

View File

@@ -24,7 +24,7 @@ class ArtistVersionsControllerTest < ActionDispatch::IntegrationTest
should respond_to_search(name: "masao").with { [@versions[2], @versions[0]] }
should respond_to_search(name_matches: "(deleted)").with { @versions[1] }
should respond_to_search(group_name_matches: "the_best").with { @versions[2] }
should respond_to_search(urls_include_any: "https://www.deviantart.com/masao").with { @versions[2] }
should respond_to_search(urls_include_any: "https://www.deviantart.com/masao").with { [@versions[2], @versions[1], @versions[0]] }
should respond_to_search(is_deleted: "true").with { @versions[1] }
context "using includes" do

View File

@@ -183,7 +183,7 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
should respond_to_search(has_tag: "false").with { [@banned, @deleted, @artgerm, @artist] }
should respond_to_search(has_urls: "true").with { [@artgerm, @masao] }
should respond_to_search(has_urls: "false").with { [@banned, @deleted, @artist] }
should respond_to_search(urls: {url: "http://www.pixiv.net/member.php?id=32777"}).with { @masao }
should respond_to_search(urls: {url: "https://www.pixiv.net/users/32777"}).with { @masao }
should respond_to_search(urls: {normalized_url: "http://www.deviantart.com/artgerm/"}).with { @artgerm }
end
end