123456789_123456789_123456789_123456789_123456789_

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

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_dispatch/journey/router/utils.rb

Overview

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

Constant Summary

Instance Method Summary

Instance Method Details

#escape(component, pattern) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 70

def escape(component, pattern)
  component.gsub(pattern) { |unsafe| percent_encode(unsafe) }.force_encoding(US_ASCII)
end

#escape_fragment(fragment)

[ GitHub ]

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

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

#escape_path(path)

[ GitHub ]

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

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

#escape_segment(segment)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 60

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

#percent_encode(unsafe) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 74

def percent_encode(unsafe)
  safe = EMPTY.dup
  unsafe.each_byte { |b| safe << DEC2HEX[b] }
  safe
end

#unescape_uri(uri)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/journey/router/utils.rb', line 64

def unescape_uri(uri)
  encoding = uri.encoding == US_ASCII ? UTF_8 : uri.encoding
  uri.gsub(ESCAPED) { |match| [match[1, 2].hex].pack("C") }.force_encoding(encoding)
end