mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 22:50:45 +08:00
b60b57cddd
This is required for people using apps with custom protocols. We still verify the entire URL (including protocol) against the site setting value. Refactored wildcard_url_checker so that it always returns a boolean, rather than sometimes returning a regex match.
22 lines
458 B
Ruby
22 lines
458 B
Ruby
# frozen_string_literal: true
|
|
|
|
module WildcardUrlChecker
|
|
def self.check_url(url, url_to_check)
|
|
return false if !valid_url?(url_to_check)
|
|
|
|
escaped_url = Regexp.escape(url).sub("\\*", '\S*')
|
|
url_regex = Regexp.new("\\A#{escaped_url}\\z", 'i')
|
|
|
|
url_to_check.match?(url_regex)
|
|
end
|
|
|
|
private
|
|
|
|
def self.valid_url?(url)
|
|
uri = URI.parse(url)
|
|
uri&.scheme.present? && uri&.host.present?
|
|
rescue URI::InvalidURIError
|
|
false
|
|
end
|
|
end
|