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:
evazion
2022-03-21 03:12:17 -05:00
parent defea08084
commit 56f47c60e1
4 changed files with 28 additions and 3 deletions

View File

@@ -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