Module: AWS::Core::UriEscape
- Included in:
- Http::Request::Param, S3::Client, S3::Request
- Defined in:
- lib/aws/core/uri_escape.rb
Overview
Provides helper methods for URI escaping values and paths.
Instance Method Summary collapse
-
#escape(value) ⇒ String
Returns a URI escaped string.
-
#escape_path(value) ⇒ String
Returns a URI-escaped path without escaping the separators.
Instance Method Details
#escape(value) ⇒ 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.
32 33 34 35 36 37 38 |
# File 'lib/aws/core/uri_escape.rb', line 32 def escape_path value escaped = "" value.scan(%r{(/*)([^/]*)(/*)}) do |(leading, part, trailing)| escaped << leading + escape(part) + trailing end escaped end |