Class: ActionDispatch::Journey::Router::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/action_dispatch/journey/router/utils.rb

Overview

:nodoc:

Defined Under Namespace

Modules: UriEscape

Constant Summary collapse

Parser =
URI.const_defined?(:Parser) ? URI::Parser.new : URI

Class Method Summary collapse

Class Method Details

.escape_fragment(fragment) ⇒ Object



47
48
49
# File 'lib/action_dispatch/journey/router/utils.rb', line 47

def self.escape_fragment(fragment)
  Parser.escape(fragment.to_s, UriEscape::UNSAFE_FRAGMENT)
end

.escape_path(path) ⇒ Object



43
44
45
# File 'lib/action_dispatch/journey/router/utils.rb', line 43

def self.escape_path(path)
  Parser.escape(path.to_s, UriEscape::UNSAFE_SEGMENT)
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"


17
18
19
20
21
22
23
24
# File 'lib/action_dispatch/journey/router/utils.rb', line 17

def self.normalize_path(path)
  path = "/#{path}"
  path.squeeze!('/')
  path.sub!(%r{/+\Z}, '')
  path.gsub!(/(%[a-f0-9]{2})/) { $1.upcase }
  path = '/' if path == ''
  path
end

.unescape_uri(uri) ⇒ Object



51
52
53
# File 'lib/action_dispatch/journey/router/utils.rb', line 51

def self.unescape_uri(uri)
  Parser.unescape(uri)
end