Class: ActionDispatch::Journey::Router::Utils
- Defined in:
- actionpack/lib/action_dispatch/journey/router/utils.rb
Overview
:nodoc:
Defined Under Namespace
Classes: UriEncoder
Constant Summary collapse
- ENCODER =
UriEncoder.new
Class Method Summary collapse
- .escape_fragment(fragment) ⇒ Object
- .escape_path(path) ⇒ Object
- .escape_segment(segment) ⇒ Object
-
.normalize_path(path) ⇒ Object
Normalizes URI path.
Class Method Details
.escape_fragment(fragment) ⇒ Object
93 94 95 |
# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 93 def self.escape_fragment(fragment) ENCODER.escape_fragment(fragment.to_s) end |
.escape_path(path) ⇒ Object
85 86 87 |
# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 85 def self.escape_path(path) ENCODER.escape_path(path.to_s) end |
.escape_segment(segment) ⇒ Object
89 90 91 |
# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 89 def self.escape_segment(segment) ENCODER.escape_segment(segment.to_s) end |
.normalize_path(path) ⇒ Object
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"
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 if path == "/" || (path.start_with?("/") && !path.end_with?("/") && !path.match?(%r{%|//})) return path.dup end # Slow path encoding = path.encoding path = +"/#{path}" path.squeeze!("/") unless path == "/" path.delete_suffix!("/") path.gsub!(/(%[a-f0-9]{2})/) { $1.upcase } end path.force_encoding(encoding) end |