diff --git a/lib/fog/providers/aws.rb b/lib/fog/providers/aws.rb index 9e8733e09..6ce4acb0b 100644 --- a/lib/fog/providers/aws.rb +++ b/lib/fog/providers/aws.rb @@ -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 diff --git a/tests/aws/signed_params_tests.rb b/tests/aws/signed_params_tests.rb new file mode 100644 index 000000000..11a36f132 --- /dev/null +++ b/tests/aws/signed_params_tests.rb @@ -0,0 +1,3 @@ +Shindo.tests('AWS | signed_params', ['aws']) do + returns( Fog::AWS.escape( "'Stop!' said Fred~" ) ) { "%27Stop%21%27%20said%20Fred~" } +end