mirror of
https://github.com/mastodon/mastodon.git
synced 2026-04-25 16:05:44 -05:00
Add Mastodon::URI_PARSE_ERRORS group for shared rescue
This commit is contained in:
parent
71092457e9
commit
c50ce7ae28
|
|
@ -56,7 +56,7 @@ class DeliveryFailureTracker
|
|||
urls.reject do |url|
|
||||
host = Addressable::URI.parse(url).normalized_host
|
||||
unavailable_domains_map[host]
|
||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||
rescue *Mastodon::URI_PARSE_ERRORS
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class TagManager
|
|||
domain = uri.host + (uri.port ? ":#{uri.port}" : '')
|
||||
|
||||
TagManager.instance.web_domain?(domain)
|
||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||
rescue *Mastodon::URI_PARSE_ERRORS
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class TextFormatter
|
|||
tag.span(display_url, class: (cutoff ? 'ellipsis' : '')) +
|
||||
tag.span(suffix, class: 'invisible')
|
||||
end
|
||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||
rescue *Mastodon::URI_PARSE_ERRORS
|
||||
h(url)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class Account::Field < ActiveModelSerializers::Model
|
|||
parsed_url.host.present? &&
|
||||
parsed_url.normalized_host == parsed_url.host &&
|
||||
(parsed_url.path.empty? || parsed_url.path == parsed_url.normalized_path)
|
||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||
rescue *Mastodon::URI_PARSE_ERRORS
|
||||
false
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class DomainBlock < ApplicationRecord
|
|||
variants = segments.map.with_index { |_, i| segments[i..].join('.') }
|
||||
|
||||
where(domain: variants).by_domain_length.first
|
||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||
rescue *Mastodon::URI_PARSE_ERRORS
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class EmailDomainBlock < ApplicationRecord
|
|||
end
|
||||
|
||||
Addressable::URI.new.tap { |u| u.host = domain.strip } if domain.present?
|
||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||
rescue *Mastodon::URI_PARSE_ERRORS
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class DomainValidator < ActiveModel::EachValidator
|
|||
uri = Addressable::URI.new
|
||||
uri.host = value
|
||||
uri.normalized_host.size < MAX_DOMAIN_LENGTH && uri.normalized_host.split('.').all? { |label| label.size.between?(MIN_LABEL_LENGTH, MAX_LABEL_LENGTH) && label =~ ALLOWED_CHARACTERS_RE }
|
||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||
rescue *Mastodon::URI_PARSE_ERRORS
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ module Mastodon
|
|||
end
|
||||
end
|
||||
|
||||
URI_PARSE_ERRORS = [
|
||||
Addressable::URI::InvalidURIError,
|
||||
IDN::Idna::IdnaError,
|
||||
].freeze
|
||||
|
||||
HTTP_CONNECTION_ERRORS = [
|
||||
HTTP::ConnectionError,
|
||||
HTTP::Error,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user