diff --git a/lib/fog/aws/simpledb.rb b/lib/fog/aws/simpledb.rb index eea986d73..8c72b9ecd 100644 --- a/lib/fog/aws/simpledb.rb +++ b/lib/fog/aws/simpledb.rb @@ -124,8 +124,8 @@ module Fog item_index = 0 for item_key in items.keys encoded_attributes["Item.#{item_index}.ItemName"] = item_key.to_s + attribute_index = 0 for attribute_key in items[item_key].keys - attribute_index = 0 for value in Array(items[item_key][attribute_key]) encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Name"] = attribute_key.to_s if replace_attributes[item_key].include?(attribute_key) @@ -134,8 +134,8 @@ module Fog encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Value"] = sdb_encode(value) attribute_index += 1 end - item_index += 1 end + item_index += 1 end end encoded_attributes diff --git a/lib/fog/providers/aws.rb b/lib/fog/providers/aws.rb index 9e8733e09..72e87be72 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/requests/simpledb/attributes_tests.rb b/tests/aws/requests/simpledb/attributes_tests.rb index e111de92a..f536b55de 100644 --- a/tests/aws/requests/simpledb/attributes_tests.rb +++ b/tests/aws/requests/simpledb/attributes_tests.rb @@ -6,11 +6,11 @@ Shindo.tests('AWS::SimpleDB | attributes requests', ['aws']) do tests('success') do - tests("#batch_put_attributes('#{@domain_name}', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } }).body").formats(AWS::SimpleDB::Formats::BASIC) do - AWS[:sdb].batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } }).body + tests("#batch_put_attributes('#{@domain_name}', { 'a' => { 'b' => 'c', 'd' => 'e' }, 'x' => { 'y' => 'z' } }).body").formats(AWS::SimpleDB::Formats::BASIC) do + AWS[:sdb].batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c', 'd' => 'e' }, 'x' => { 'y' => 'z' } }).body end - tests("#get_attributes('#{@domain_name}', 'a').body['Attributes']").returns({'b' => ['c']}) do + tests("#get_attributes('#{@domain_name}', 'a').body['Attributes']").returns({'b' => ['c'], 'd' => ['e']}) do attributes = {} Fog.wait_for { attributes = AWS[:sdb].get_attributes(@domain_name, 'a').body['Attributes'] @@ -23,7 +23,7 @@ Shindo.tests('AWS::SimpleDB | attributes requests', ['aws']) do AWS[:sdb].get_attributes(@domain_name, 'notanattribute') end - tests("#select('select * from #{@domain_name}').body['Items']").returns({ 'a' => { 'b' => ['c'] }, 'x' => { 'y' => ['z'] } }) do + tests("#select('select * from #{@domain_name}').body['Items']").returns({'a' => { 'b' => ['c'], 'd' => ['e']}, 'x' => { 'y' => ['z'] } }) do pending if Fog.mocking? AWS[:sdb].select("select * from #{@domain_name}").body['Items'] end diff --git a/tests/aws/signed_params_tests.rb b/tests/aws/signed_params_tests.rb new file mode 100644 index 000000000..24ffec3d0 --- /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