class Sanitize::URISanitizer
- Sanitize::URISanitizer
- Reference
- Object
Overview
A URISanitizer
is used to validate and transform a URI based on specified
rules.
Defined in:
uri_sanitizer.crConstructors
Instance Method Summary
-
#accept_scheme(scheme : String)
Adds scheme to
#accepted_schemes
. -
#accepted_hosts : Set(String) | Nil
Specifies a whitelist of hosts this sanitizer accepts.
-
#accepted_hosts=(accepted_hosts : Set(String) | Nil)
Specifies a whitelist of hosts this sanitizer accepts.
-
#accepted_schemes : Set(String) | Nil
Specifies a whitelist of URI schemes this sanitizer accepts.
-
#accepted_schemes=(accepted_schemes : Set(String) | Nil)
Specifies a whitelist of URI schemes this sanitizer accepts.
- #accepts_host?(host)
- #accepts_scheme?(scheme)
-
#base_url : URI | Nil
Specifies a base URL all relative URLs are resolved against.
-
#base_url=(base_url : URI | Nil)
Specifies a base URL all relative URLs are resolved against.
-
#rejected_hosts : Set(String)
Specifies a blacklist of hosts this sanitizer rejects.
-
#rejected_hosts=(rejected_hosts : Set(String))
Specifies a blacklist of hosts this sanitizer rejects.
- #resolve_base_url(uri)
-
#resolve_fragment_urls : Bool
Configures whether fragment-only URIs are resolved on
#base_url
. -
#resolve_fragment_urls=(resolve_fragment_urls : Bool)
Configures whether fragment-only URIs are resolved on
#base_url
. - #sanitize(uri : URI) : URI | Nil
Constructor Detail
Instance Method Detail
Specifies a whitelist of hosts this sanitizer accepts.
If empty, no hosts are accepted (i.e. only relative URIs are valid).
If nil
, all hosts are accepted (default).
The blacklist #rejected_hosts
has precedence over this whitelist.
Specifies a whitelist of hosts this sanitizer accepts.
If empty, no hosts are accepted (i.e. only relative URIs are valid).
If nil
, all hosts are accepted (default).
The blacklist #rejected_hosts
has precedence over this whitelist.
Specifies a whitelist of URI schemes this sanitizer accepts.
If empty, no schemes are accepted (i.e. only relative URIs are valid).
If nil
, all schemes are accepted (this setting is potentially dangerous).
Relative URIs are not affected by this setting.
Specifies a whitelist of URI schemes this sanitizer accepts.
If empty, no schemes are accepted (i.e. only relative URIs are valid).
If nil
, all schemes are accepted (this setting is potentially dangerous).
Relative URIs are not affected by this setting.
Specifies a base URL all relative URLs are resolved against.
If nil
, relative URLs are not resolved.
Specifies a base URL all relative URLs are resolved against.
If nil
, relative URLs are not resolved.
Specifies a blacklist of hosts this sanitizer rejects.
If empty, no hosts are rejected.
This blacklist has precedence over the whitelist #accepted_hosts
.
Specifies a blacklist of hosts this sanitizer rejects.
If empty, no hosts are rejected.
This blacklist has precedence over the whitelist #accepted_hosts
.
Configures whether fragment-only URIs are resolved on #base_url
.
sanitizer = Sanitize::URISanitizer.new
sanitizer.base_url = URI.parse("https://example.com/base/")
sanitizer.sanitize(URI.parse("#foo")) # => "#foo"
sanitizer.resolve_fragment_urls = true
sanitizer.sanitize(URI.parse("#foo")) # => "https://example.com/base/#foo"
Configures whether fragment-only URIs are resolved on #base_url
.
sanitizer = Sanitize::URISanitizer.new
sanitizer.base_url = URI.parse("https://example.com/base/")
sanitizer.sanitize(URI.parse("#foo")) # => "#foo"
sanitizer.resolve_fragment_urls = true
sanitizer.sanitize(URI.parse("#foo")) # => "https://example.com/base/#foo"