posts: fix exception when viewing post with source Blog..
Fix a PublicSuffix::DomainNotAllowed exception raised with viewing or editing a post
with a source like `Blog.`.
This happened when parsing the post's source. `Danbooru::URL.parse("Blog.")` would
heuristically parse the source into `http://blog`. Calling any methods related to the
URL's hostname or domain would lead to calling `PublicSuffix.parse("blog")`, which
would fail with PublicSuffix::DomainNotAllowed.
This commit is contained in:
@@ -45,6 +45,7 @@ module Danbooru
|
||||
@url.path = nil if @url.path == "/"
|
||||
|
||||
raise Error, "#{original_url} is not an http:// URL" if !@url.normalized_scheme.in?(["http", "https"])
|
||||
raise Error, "#{original_url} is not a valid hostname" if parsed_domain.nil?
|
||||
rescue Addressable::URI::InvalidURIError => e
|
||||
raise Error, e
|
||||
end
|
||||
@@ -113,6 +114,8 @@ module Danbooru
|
||||
# @return [PublicSuffix::Domain]
|
||||
def parsed_domain
|
||||
@parsed_domain ||= PublicSuffix.parse(host)
|
||||
rescue PublicSuffix::DomainNotAllowed
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user