artist urls: normalize trailing slashes and missing http://.

* Remove unnecessary trailing slashes when artist URLs are saved.
* Automatically add `http://` to new artist URLs if it's missing (before
  this was an error; now it's automatically fixed).
This commit is contained in:
evazion
2022-02-21 18:57:40 -06:00
parent 7d49ab6130
commit c5777f360e
3 changed files with 18 additions and 19 deletions

View File

@@ -72,8 +72,7 @@ class ArtistURL < ApplicationRecord
end
def domain
uri = Addressable::URI.parse(normalized_url)
uri.domain
Danbooru::URL.parse(normalized_url)&.domain
end
def site_name
@@ -119,11 +118,7 @@ class ArtistURL < ApplicationRecord
end
def self.normalize_url(url)
uri = Addressable::URI.parse(url)
uri.site = uri.normalized_site
uri.to_s
rescue Addressable::URI::InvalidURIError
url
Danbooru::URL.parse(url)&.to_s.presence || url
end
def url=(url)