Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't Read IO Objects in Attribute Value Marshal #832

Merged
merged 2 commits into from
Jun 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aws-sdk-core/lib/aws-sdk-core/dynamodb/attribute_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def format(obj)
end
when String then { s: obj }
when Numeric then { n: obj.to_s }
when StringIO, IO then { b: obj.read }
when StringIO, IO then { b: obj }
when Set then format_set(obj)
when true, false then { bool: obj }
when nil then { null: true }
Expand All @@ -51,7 +51,7 @@ def format_set(set)
case set.first
when String then { ss: set.map(&:to_s) }
when Numeric then { ns: set.map(&:to_s) }
when StringIO, IO then { bs: set.map(&:read) }
when StringIO, IO then { bs: set.to_a }
else
msg = "set types only support String, Numeric, or IO objects"
raise ArgumentError, msg
Expand Down
11 changes: 9 additions & 2 deletions aws-sdk-core/spec/aws/dynamodb/attribute_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ module DynamoDB
])
end

it 'converts IO objects to :b (binary)' do
io = StringIO.new('bar')
formatted = value.marshal(foo: io)
expect(formatted[:m]["foo"][:b].read).to eq('bar')
end

it 'converts string sets to :ss (string set)' do
formatted = value.marshal(Set.new(%w(abc mno)))
expect(formatted).to eq(ss: %w(abc mno))
Expand All @@ -37,8 +43,9 @@ module DynamoDB
end

it 'converts binary sets to :bs (binary set)' do
formatted = value.marshal(Set.new([StringIO.new('data')]))
expect(formatted).to eq(bs: ['data'])
io_obj = StringIO.new('data')
formatted = value.marshal(Set.new([io_obj]))
expect(formatted).to eq(bs: [io_obj])
end

it 'converts numerics to :n (number)' do
Expand Down