Fix #4440: Whitespace not trimmed when searching by URL in Artists.
This commit is contained in:
@@ -222,6 +222,8 @@ class Artist < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def url_matches(query)
|
def url_matches(query)
|
||||||
|
query = query.strip
|
||||||
|
|
||||||
if query =~ %r!\A/(.*)/\z!
|
if query =~ %r!\A/(.*)/\z!
|
||||||
where(id: ArtistUrl.where_regex(:url, $1).select(:artist_id))
|
where(id: ArtistUrl.where_regex(:url, $1).select(:artist_id))
|
||||||
elsif query.include?("*")
|
elsif query.include?("*")
|
||||||
@@ -234,6 +236,8 @@ class Artist < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def any_name_or_url_matches(query)
|
def any_name_or_url_matches(query)
|
||||||
|
query = query.strip
|
||||||
|
|
||||||
if query =~ %r!\Ahttps?://!i
|
if query =~ %r!\Ahttps?://!i
|
||||||
url_matches(query)
|
url_matches(query)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -142,6 +142,12 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
get artists_path(search: { url_matches: url }, format: "json")
|
get artists_path(search: { url_matches: url }, format: "json")
|
||||||
assert_artist_found("masao")
|
assert_artist_found("masao")
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user