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 69

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 51

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

#escape_path(path)

[ GitHub ]

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

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

#escape_segment(segment)

[ GitHub ]

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

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

#percent_encode(unsafe) (private)

[ GitHub ]

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

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 63

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