diff --git a/app/models/artist.rb b/app/models/artist.rb index f4d2d0c7e..692ff39fe 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -222,6 +222,8 @@ class Artist < ApplicationRecord end def url_matches(query) + query = query.strip + if query =~ %r!\A/(.*)/\z! where(id: ArtistUrl.where_regex(:url, $1).select(:artist_id)) elsif query.include?("*") @@ -234,6 +236,8 @@ class Artist < ApplicationRecord end def any_name_or_url_matches(query) + query = query.strip + if query =~ %r!\Ahttps?://!i url_matches(query) else diff --git a/test/functional/artists_controller_test.rb b/test/functional/artists_controller_test.rb index c4f1714e6..97697622b 100644 --- a/test/functional/artists_controller_test.rb +++ b/test/functional/artists_controller_test.rb @@ -142,6 +142,12 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest get artists_path(search: { url_matches: url }, format: "json") assert_artist_found("masao") end + + should "ignore whitespace when searching by URL" do + url = " http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46170939 " + get artists_path(search: { url_matches: url }, format: "json") + assert_artist_found("masao") + end end end