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:
parent
e6332f34bc
commit
9f25c5c6a3
2 changed files with 8 additions and 1 deletions
|
@ -41,6 +41,10 @@ module Fog
|
||||||
params
|
params
|
||||||
end
|
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 = {})
|
def self.signed_params(params, options = {})
|
||||||
params.merge!({
|
params.merge!({
|
||||||
'AWSAccessKeyId' => options[:aws_access_key_id],
|
'AWSAccessKeyId' => options[:aws_access_key_id],
|
||||||
|
@ -53,7 +57,7 @@ module Fog
|
||||||
body = ''
|
body = ''
|
||||||
for key in params.keys.sort
|
for key in params.keys.sort
|
||||||
unless (value = params[key]).nil?
|
unless (value = params[key]).nil?
|
||||||
body << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
|
body << "#{key}=#{escape(value.to_s)}&"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
string_to_sign = "POST\n#{options[:host]}:#{options[:port]}\n#{options[:path]}\n" << body.chop
|
string_to_sign = "POST\n#{options[:host]}:#{options[:port]}\n#{options[:path]}\n" << body.chop
|
||||||
|
|
3
tests/aws/signed_params_tests.rb
Normal file
3
tests/aws/signed_params_tests.rb
Normal 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
|
Loading…
Reference in a new issue