Skip to content

Commit

Permalink
Merge pull request #832 from aws/issue831
Browse files Browse the repository at this point in the history
Don't Read IO Objects in Attribute Value Marshal
  • Loading branch information
trevorrowe committed Jun 3, 2015
2 parents be9b131 + 2e23d35 commit 00fbe63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
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

0 comments on commit 00fbe63

Please sign in to comment.