Skip to content
Snippets Groups Projects
Unverified Commit 51ff679b authored by ThibG's avatar ThibG Committed by GitHub
Browse files

Fix admin page crashing when trying to block an invalid domain name (#13884)

* Fix admin page crashing when trying to block an invalid domain name

Fixes #13880

* Fix trailing and leading spaces not being properly stripped for domain blocks
parent eeddb1a6
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ module DomainNormalizable
extend ActiveSupport::Concern
included do
before_save :normalize_domain
before_validation :normalize_domain
end
private
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment