2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 09:10:25 +08:00
discourse/app/services/wildcard_domain_checker.rb
2019-12-13 09:29:09 -05:00

12 lines
328 B
Ruby

# frozen_string_literal: true
module WildcardDomainChecker
def self.check_domain(domain, external_domain)
escaped_domain = domain[0] == "*" ? Regexp.escape(domain).sub("\\*", '\S*') : Regexp.escape(domain)
domain_regex = Regexp.new("\\A#{escaped_domain}\\z", 'i')
external_domain.match(domain_regex)
end
end