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

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

Overview

URI path and fragment escaping tools.ietf.org/html/rfc3986

Constant Summary collapse

ENCODE =

:nodoc:

"%%%02X".freeze
ENCODING =
Encoding::US_ASCII
EMPTY =
"".force_encoding(ENCODING).freeze
DEC2HEX =
(0..255).to_a.map{ |i| ENCODE % i }.map{ |s| s.force_encoding(ENCODING) }
ALPHA =
"a-zA-Z".freeze
DIGIT =
"0-9".freeze
UNRESERVED =
"#{ALPHA}#{DIGIT}\\-\\._~".freeze
SUB_DELIMS =
"!\\$&'\\(\\)\\*\\+,;=".freeze
ESCAPED =
/%[a-zA-Z0-9]{2}/.freeze
FRAGMENT =
/[^#{UNRESERVED}#{SUB_DELIMS}:@\/\?]/.freeze
SEGMENT =
/[^#{UNRESERVED}#{SUB_DELIMS}:@]/.freeze
PATH =
/[^#{UNRESERVED}#{SUB_DELIMS}:@\/]/.freeze

Instance Method Summary collapse

Instance Method Details

#escape_fragment(fragment) ⇒ Object



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

def escape_fragment(fragment)
  escape(fragment, FRAGMENT)
end

#escape_path(path) ⇒ Object



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

def escape_path(path)
  escape(path, PATH)
end

#escape_segment(segment) ⇒ Object



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

def escape_segment(segment)
  escape(segment, SEGMENT)
end

#unescape_uri(uri) ⇒ Object



55
56
57
# File 'lib/action_dispatch/journey/router/utils.rb', line 55

def unescape_uri(uri)
  uri.gsub(ESCAPED) { [$&[1, 2].hex].pack('C') }.force_encoding(uri.encoding)
end