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:
@@ -70,8 +70,7 @@ class Upload < ApplicationRecord
|
||||
class_methods do
|
||||
# percent-encode unicode characters in the URL
|
||||
def normalize_source(url)
|
||||
return nil if url.nil?
|
||||
Addressable::URI.normalized_encode(url)
|
||||
Danbooru::URL.parse(url)&.to_s.presence || url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user