about summary refs log tree commit diff
path: root/app/models/domain_block.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/domain_block.rb')
-rw-r--r--app/models/domain_block.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb
index f0a5bd296..2b18e01fa 100644
--- a/app/models/domain_block.rb
+++ b/app/models/domain_block.rb
@@ -50,11 +50,13 @@ class DomainBlock < ApplicationRecord
     def rule_for(domain)
       return if domain.blank?
 
-      uri      = Addressable::URI.new.tap { |u| u.host = domain.gsub(/[\/]/, '') }
+      uri      = Addressable::URI.new.tap { |u| u.host = domain.strip.gsub(/[\/]/, '') }
       segments = uri.normalized_host.split('.')
       variants = segments.map.with_index { |_, i| segments[i..-1].join('.') }
 
       where(domain: variants).order(Arel.sql('char_length(domain) desc')).first
+    rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
+      nil
     end
   end