Add Danbooru::URL class.
Introduce a Danbooru::URL class for dealing with URLs. This is a wrapper around Addressable::URI that adds some additional helper methods. Most significantly, the `parse` method only allows valid http/https URLs, and it returns nil instead of raising an exception when the URL is invalid.
This commit is contained in:
@@ -314,10 +314,7 @@ class Post < ApplicationRecord
|
||||
def source_domain
|
||||
return "" unless source =~ %r{\Ahttps?://}i
|
||||
|
||||
url = Addressable::URI.parse(normalized_source)
|
||||
url.domain
|
||||
rescue StandardError
|
||||
""
|
||||
Danbooru::URL.parse(normalized_source)&.domain.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user