Class: ActionDispatch::Journey::Router::Utils
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Inherits: | Object |
| Defined in: | actionpack/lib/action_dispatch/journey/router/utils.rb |
Constant Summary
Class Method Summary
- .escape_fragment(fragment)
- .escape_path(path)
- .escape_segment(segment)
-
.normalize_path(path)
Normalizes URI path.
-
.normalized_path?(path) ⇒ Boolean
Whether normalize_path's fast path applies: the path is already in normalized form and would come back unchanged, apart from the copy, so hot paths can skip the call and the copy entirely.
Class Method Details
.escape_fragment(fragment)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 105
def self.escape_fragment(fragment) ENCODER.escape_fragment(fragment.to_s) end
.escape_path(path)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 97
def self.escape_path(path) ENCODER.escape_path(path.to_s) end
.escape_segment(segment)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 101
def self.escape_segment(segment) ENCODER.escape_segment(segment.to_s) end
.normalize_path(path)
Normalizes URI path.
Strips off trailing slash and ensures there is a leading slash. Also converts downcase URL encoded string to uppercase.
normalize_path("/foo") # => "/foo"
normalize_path("/foo/") # => "/foo"
normalize_path("foo") # => "/foo"
normalize_path("") # => "/"
normalize_path("/%ab") # => "/%AB"
# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 19
def self.normalize_path(path) return "/".dup unless path # Fast path for the overwhelming majority of paths that don't need # to be normalized. Callers may mutate the result (the route mapper # does), so the input is still copied. if normalized_path?(path) return path.dup end # Slow path encoding = path.encoding path = +"/#{path}" path.squeeze!("/") unless path == "/" path.delete_suffix!("/") path.gsub!(/(%[a-f0-9]{2})/i) { $1.upcase } end path.force_encoding(encoding) end
.normalized_path?(path) ⇒ Boolean
Whether normalize_path's fast path applies: the path is already in normalized form and would come back unchanged, apart from the copy, so hot paths can skip the call and the copy entirely. Conservative by design: a path with percent escapes is reported as not normalized even when they are already uppercase.
# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 47
def self.normalized_path?(path) return false unless path path == "/" || (path.start_with?("/") && !path.end_with?("/") && !path.match?(%r{%|//})) end