1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Fix a problem with the encoding of the tilde character. AWS needs tilde to be unescaped, or else the signature fails. CGI.escape escapes tilde; don't use it.

This commit is contained in:
Joshua Napoli 2011-04-09 20:16:42 -04:00
parent e6332f34bc
commit 9f25c5c6a3
2 changed files with 8 additions and 1 deletions

View file

@ -41,6 +41,10 @@ module Fog
params
end
def self.escape(string)
string.gsub( /([^a-zA-Z0-9_.-~]+)/n ) { |match| '%' + match.unpack( 'H2' * match.size ).join( '%' ).upcase }
end
def self.signed_params(params, options = {})
params.merge!({
'AWSAccessKeyId' => options[:aws_access_key_id],
@ -53,7 +57,7 @@ module Fog
body = ''
for key in params.keys.sort
unless (value = params[key]).nil?
body << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
body << "#{key}=#{escape(value.to_s)}&"
end
end
string_to_sign = "POST\n#{options[:host]}:#{options[:port]}\n#{options[:path]}\n" << body.chop

View file

@ -0,0 +1,3 @@
Shindo.tests('AWS | signed_params', ['aws']) do
returns( Fog::AWS.escape( "'Stop!' said Fred~" ) ) { "%27Stop%21%27%20said%20Fred~" }
end