mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-12-22 13:17:13 +00:00
Strip spaces around URL when adding a relay (#22655)
* Strip spaces around URL when adding a relay Fixes #22650 * Gracefuly handle URL parsing errors in URL validator
This commit is contained in:
parent
b3ab0014e6
commit
3654c94583
|
@ -18,6 +18,7 @@ class Relay < ApplicationRecord
|
||||||
|
|
||||||
scope :enabled, -> { accepted }
|
scope :enabled, -> { accepted }
|
||||||
|
|
||||||
|
before_validation :strip_url
|
||||||
before_destroy :ensure_disabled
|
before_destroy :ensure_disabled
|
||||||
|
|
||||||
alias enabled? accepted?
|
alias enabled? accepted?
|
||||||
|
@ -74,4 +75,8 @@ class Relay < ApplicationRecord
|
||||||
def ensure_disabled
|
def ensure_disabled
|
||||||
disable! if enabled?
|
disable! if enabled?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def strip_url
|
||||||
|
inbox_url&.strip!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,5 +10,7 @@ class URLValidator < ActiveModel::EachValidator
|
||||||
def compliant?(url)
|
def compliant?(url)
|
||||||
parsed_url = Addressable::URI.parse(url)
|
parsed_url = Addressable::URI.parse(url)
|
||||||
parsed_url && %w(http https).include?(parsed_url.scheme) && parsed_url.host
|
parsed_url && %w(http https).include?(parsed_url.scheme) && parsed_url.host
|
||||||
|
rescue Addressable::URI::InvalidURIError
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue