From 867a352a0f6ba6084cd0a13055104d527f272757 Mon Sep 17 00:00:00 2001 From: croaker Date: Tue, 12 Jul 2011 15:59:51 +0200 Subject: [PATCH 1/2] Fixed escaping in Fog::AWS.escape Now correctly escapes multibyte strings and behaves exactly like CGI.escape except that the tilde char is not escaped. --- lib/fog/providers/aws.rb | 4 +++- tests/aws/signed_params_tests.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/fog/providers/aws.rb b/lib/fog/providers/aws.rb index 9138da2eb..c961975aa 100644 --- a/lib/fog/providers/aws.rb +++ b/lib/fog/providers/aws.rb @@ -46,7 +46,9 @@ module Fog end def self.escape(string) - string.gsub( /([^-a-zA-Z0-9_.~]+)/n ) { |match| '%' + match.unpack( 'H2' * match.size ).join( '%' ).upcase } + string.gsub(/([^ a-zA-Z0-9_.\-~]+)/) { + "%" + $1.unpack("H2" * $1.bytesize).join("%").upcase + }.tr(" ", "+") end def self.signed_params(params, options = {}) diff --git a/tests/aws/signed_params_tests.rb b/tests/aws/signed_params_tests.rb index 24ffec3d0..d93fc8e11 100644 --- a/tests/aws/signed_params_tests.rb +++ b/tests/aws/signed_params_tests.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + Shindo.tests('AWS | signed_params', ['aws']) do - returns( Fog::AWS.escape( "'Stop!' said Fred_-~." ) ) { "%27Stop%21%27%20said%20Fred_-~." } + returns( Fog::AWS.escape( "'Stöp!' said Fred_-~." ) ) { "%27St%C3%B6p%21%27+said+Fred_-~." } end From bfa6685c7fa776d1ce9f120d2db1dd0476ed10f4 Mon Sep 17 00:00:00 2001 From: croaker Date: Wed, 13 Jul 2011 11:13:59 +0200 Subject: [PATCH 2/2] Changed the encoding of the space character Space characters are now encoded as %20. This is recommended in: http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?using-query-api.html --- lib/fog/providers/aws.rb | 4 ++-- tests/aws/signed_params_tests.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fog/providers/aws.rb b/lib/fog/providers/aws.rb index c961975aa..7ef39795c 100644 --- a/lib/fog/providers/aws.rb +++ b/lib/fog/providers/aws.rb @@ -46,9 +46,9 @@ module Fog end def self.escape(string) - string.gsub(/([^ a-zA-Z0-9_.\-~]+)/) { + string.gsub(/([^a-zA-Z0-9_.\-~]+)/) { "%" + $1.unpack("H2" * $1.bytesize).join("%").upcase - }.tr(" ", "+") + } end def self.signed_params(params, options = {}) diff --git a/tests/aws/signed_params_tests.rb b/tests/aws/signed_params_tests.rb index d93fc8e11..1df3950de 100644 --- a/tests/aws/signed_params_tests.rb +++ b/tests/aws/signed_params_tests.rb @@ -1,5 +1,5 @@ # encoding: utf-8 Shindo.tests('AWS | signed_params', ['aws']) do - returns( Fog::AWS.escape( "'Stöp!' said Fred_-~." ) ) { "%27St%C3%B6p%21%27+said+Fred_-~." } + returns( Fog::AWS.escape( "'Stöp!' said Fred_-~." ) ) { "%27St%C3%B6p%21%27%20said%20Fred_-~." } end