about summary refs log tree commit diff
path: root/app/validators
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-08-30 02:19:17 +0200
committerGitHub <noreply@github.com>2019-08-30 02:19:17 +0200
commitb54b725d6bc8dd0a4ab0fe0bf408193c1bae8106 (patch)
tree2e0f0477b75ad45866ec62db62be93d4b467856c /app/validators
parent6914482d0a6e7e654e17e7f2aa2f6a2acde6c59a (diff)
Fix uncaught domain normalization error in remote follow (#11703)
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/domain_validator.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/validators/domain_validator.rb b/app/validators/domain_validator.rb
index ae07f1798..6e4a854ff 100644
--- a/app/validators/domain_validator.rb
+++ b/app/validators/domain_validator.rb
@@ -4,14 +4,22 @@ class DomainValidator < ActiveModel::EachValidator
   def validate_each(record, attribute, value)
     return if value.blank?
 
-    record.errors.add(attribute, I18n.t('domain_validator.invalid_domain')) unless compliant?(value)
+    domain = begin
+      if options[:acct]
+        value.split('@').last
+      else
+        value
+      end
+    end
+
+    record.errors.add(attribute, I18n.t('domain_validator.invalid_domain')) unless compliant?(domain)
   end
 
   private
 
   def compliant?(value)
     Addressable::URI.new.tap { |uri| uri.host = value }
-  rescue Addressable::URI::InvalidURIError
+  rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
     false
   end
 end