18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/models/embeddable_host.rb', line 18
def self.record_for_url(uri)
if uri.is_a?(String)
uri =
begin
URI(UrlHelper.normalized_encode(uri))
rescue URI::Error, Addressable::URI::InvalidURIError
end
end
return false if uri.blank?
host = uri.host
return false if host.blank?
host << ":#{uri.port}" if uri.port.present? && uri.port != 80 && uri.port != 443
path = uri.path
path << "?" << uri.query if uri.query.present?
where("lower(host) = ?", host).each do |eh|
return eh if eh.allowed_paths.blank?
path_regexp = Regexp.new(eh.allowed_paths)
return eh if path_regexp.match(path) || path_regexp.match(UrlHelper.unencode(path))
end
nil
end
|