Module: AWS::Core::UriEscape

Included in:
S3::Client
Defined in:
lib/aws/core/uri_escape.rb

Overview

Provides helper methods for URI escaping values and paths.

Class Method Summary collapse

Class Method Details

.escape(value) ⇒ String

Returns a URI escaped string.

Parameters:

  • value (String)

Returns:

  • (String)

    Returns a URI escaped string.



24
25
26
27
# File 'lib/aws/core/uri_escape.rb', line 24

def escape value
  value = value.encode("UTF-8") if value.respond_to?(:encode)
  CGI::escape(value.to_s).gsub('+', '%20').gsub('%7E', '~')
end

.escape_path(value) ⇒ String

Returns a URI-escaped path without escaping the separators.

Parameters:

  • value (String)

Returns:

  • (String)

    Returns a URI-escaped path without escaping the separators.



33
34
35
36
37
38
39
# File 'lib/aws/core/uri_escape.rb', line 33

def escape_path value
  escaped = ""
  value.scan(%r{(/*)([^/]*)(/*)}) do |(leading, part, trailing)|
    escaped << leading + escape(part) + trailing
  end
  escaped
end