Module: Redmine::Helpers::URL

Included in:
ApplicationHelper, RedCloth3, FieldFormat::Base, WikiFormatting::Markdown::HTML
Defined in:
lib/redmine/helpers/url.rb

Instance Method Summary collapse

Instance Method Details

#uri_with_safe_scheme?(uri, schemes = ['http', 'https', 'ftp', 'mailto', nil]) ⇒ Boolean

Returns:

  • (Boolean)

25
26
27
28
29
30
31
32
33
34
# File 'lib/redmine/helpers/url.rb', line 25

def uri_with_safe_scheme?(uri, schemes = ['http', 'https', 'ftp', 'mailto', nil])
  # URLs relative to the current document or document root (without a protocol
  # separator, should be harmless
  return true unless uri.to_s.include? ":"

  # Other URLs need to be parsed
  schemes.include? URI.parse(uri).scheme
rescue URI::Error
  false
end