about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/models/relay.rb5
-rw-r--r--app/validators/url_validator.rb2
2 files changed, 7 insertions, 0 deletions
diff --git a/app/models/relay.rb b/app/models/relay.rb
index d6ddd30ed..c66bfe4ff 100644
--- a/app/models/relay.rb
+++ b/app/models/relay.rb
@@ -18,6 +18,7 @@ class Relay < ApplicationRecord
 
   scope :enabled, -> { accepted }
 
+  before_validation :strip_url
   before_destroy :ensure_disabled
 
   alias enabled? accepted?
@@ -74,4 +75,8 @@ class Relay < ApplicationRecord
   def ensure_disabled
     disable! if enabled?
   end
+
+  def strip_url
+    inbox_url&.strip!
+  end
 end
diff --git a/app/validators/url_validator.rb b/app/validators/url_validator.rb
index 75d1edb87..a90fb6958 100644
--- a/app/validators/url_validator.rb
+++ b/app/validators/url_validator.rb
@@ -10,5 +10,7 @@ class URLValidator < ActiveModel::EachValidator
   def compliant?(url)
     parsed_url = Addressable::URI.parse(url)
     parsed_url && %w(http https).include?(parsed_url.scheme) && parsed_url.host
+  rescue Addressable::URI::InvalidURIError
+    false
   end
 end