From be9b1311fb23eb376f78811325ce5d6a6f2e3187 Mon Sep 17 00:00:00 2001 From: Trevor Rowe Date: Thu, 28 May 2015 17:50:22 -0700 Subject: [PATCH] Bug fix on url decoding keys. Fixes #828 --- CHANGELOG.md | 7 ++++++- aws-sdk-core/features/s3/objects.feature | 8 ++++++++ aws-sdk-core/features/s3/step_definitions.rb | 5 +++++ .../lib/aws-sdk-core/plugins/s3_url_encoded_keys.rb | 6 +++--- aws-sdk-core/spec/aws/s3/client_spec.rb | 3 ++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0017291c49f..a5d77192a16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Unreleased Changes ------------------ +* Issue - Aws::S3 - Resolved an issue with the URL decoding of keys in the + response to a call to `Aws::S3::Client#list_objects`. + + See [related GitHub issue #828](https://github.com/aws/aws-sdk-ruby/pull/828) + 2.0.47 (2015-05-28) ------------------ @@ -23,7 +28,7 @@ Unreleased Changes * Feature - Aws::ElasticTranscoder - Elastic Transcoder now supports additional formats, including MXF, FLAC, and OGA, and additional flexibility for your output audio. You can use these formats to transcode files to the XDCAM format - or to a lossless audio format. + or to a lossless audio format. * Feature - Aws::Kinesis - The Amazon Kinesis API `#get_records` now includes a new parameter `:millis_behind_latest`: the number of milliseconds the diff --git a/aws-sdk-core/features/s3/objects.feature b/aws-sdk-core/features/s3/objects.feature index 0f4b2875d22..72e9015a8e8 100644 --- a/aws-sdk-core/features/s3/objects.feature +++ b/aws-sdk-core/features/s3/objects.feature @@ -31,6 +31,14 @@ Feature: S3 Objects When I get an object that doesn't exist with a read block Then an error should be raise and the block should not yield + Scenario: URL decoding Keys + Given I put "data1" to the key "a b" + And I put "data2" to the key "a+b" + Then the keys in my bucket should be + | keys | + | a b | + | a+b | + @paging Scenario: Paging responses Given I put nothing to the key "photos/camping/cascades.jpg" diff --git a/aws-sdk-core/features/s3/step_definitions.rb b/aws-sdk-core/features/s3/step_definitions.rb index 26971d410f8..6be97e02bcf 100644 --- a/aws-sdk-core/features/s3/step_definitions.rb +++ b/aws-sdk-core/features/s3/step_definitions.rb @@ -253,3 +253,8 @@ def create_bucket(options = {}) resp = @client.list_objects(bucket: @bucket_name, prefix: key, max_keys: 1) expect(resp.contents.first.storage_class).to eq(sc) end + +Then(/^the keys in my bucket should be$/) do |table| + keys = @client.list_objects(bucket:@bucket_name).contents.map(&:key) + expect(keys.sort).to eq(table.rows.map(&:first).sort) +end diff --git a/aws-sdk-core/lib/aws-sdk-core/plugins/s3_url_encoded_keys.rb b/aws-sdk-core/lib/aws-sdk-core/plugins/s3_url_encoded_keys.rb index 947005e0747..1ae0bf9e8d7 100644 --- a/aws-sdk-core/lib/aws-sdk-core/plugins/s3_url_encoded_keys.rb +++ b/aws-sdk-core/lib/aws-sdk-core/plugins/s3_url_encoded_keys.rb @@ -71,15 +71,15 @@ def decode_list_multipart_uploads_keys(data) def decode(member, struct) if struct[member] - struct[member] = URI.decode(struct[member]) + struct[member] = CGI.unescape(struct[member]) end end end handler(Handler, - step: :build, - priority: 60, # run this just before/after the XML builder/parser + step: :validate, + priority: 0, operations: [ :list_objects, :list_object_versions, diff --git a/aws-sdk-core/spec/aws/s3/client_spec.rb b/aws-sdk-core/spec/aws/s3/client_spec.rb index c5a95dee641..3192985e580 100644 --- a/aws-sdk-core/spec/aws/s3/client_spec.rb +++ b/aws-sdk-core/spec/aws/s3/client_spec.rb @@ -244,6 +244,7 @@ module S3 Seahorse::Client::Response.new(context: context) end resp = client.list_objects(bucket:'aws-sdk') + expect(resp.context.http_request.endpoint.query).to include('encoding-type=url') expect(resp.context.params[:encoding_type]).to eq('url') expect(resp.data.to_h).to eq({ prefix: 'a&', @@ -416,7 +417,7 @@ module S3 end resp = client.list_objects(bucket:'aws-sdk') expect(resp.contents.map(&:key)).to eq([ - 'prefix+suffix', + 'prefix suffix', 'prefix+suffix', 'prefix suffix', ])