Skip to content

Commit

Permalink
Fix StorageObject#metadata for 1.9.2
Browse files Browse the repository at this point in the history
In ruby 1.8.7, Array#to_s behaves like:

>> ['a',1,'b',2].to_s
=> "a1b2"

In ruby 1.9.2 however:

>> ['a',1,'b',2].to_s
=> "["a", 1, "b", 2]"

This means that StorageObject#metadata is returning mangled values for those headers. This fix should replicate the 1.8.7 behavior in 1.9.2. 

Tests are included and pass (for that specific test) in both 1.8.7 and 1.9.2
  • Loading branch information
slyphon committed Jul 29, 2011
1 parent e119320 commit 1d3d3f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/cloudfiles/storage_object.rb
Expand Up @@ -45,7 +45,12 @@ def object_metadata
response = self.container.connection.cfreq("HEAD", @storagehost, @storagepath, @storageport, @storagescheme)
raise CloudFiles::Exception::NoSuchObject, "Object #{@name} does not exist" unless (response.code =~ /^20/)
resphash = {}
response.to_hash.select { |k,v| k.match(/^x-object-meta/) }.each { |x| resphash[x[0]] = x[1].to_s }
metas = response.to_hash.select { |k,v| k.match(/^x-object-meta/) }

metas.each do |x,y|
resphash[x] = (y.respond_to?(:join) ? y.join('') : y.to_s)
end

{
:manifest => response["x-object-manifest"],
:bytes => response["content-length"],
Expand Down
4 changes: 2 additions & 2 deletions test/cloudfiles_storage_object_test.rb
Expand Up @@ -109,12 +109,12 @@ def test_set_metadata_fails

def test_read_metadata_succeeds
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-object-meta-foo' => 'Bar', 'last-modified' => Time.now.to_s}
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-object-meta-foo' => 'Bar', 'x-object-meta-spam' => ['peanut', 'butter'], 'last-modified' => Time.now.to_s}
response.stubs(:code).returns('204')
connection.stubs(:cfreq => response)
container = CloudFiles::Container.new(connection, 'test_container')
@object = CloudFiles::StorageObject.new(container, 'test_object')
assert_equal @object.metadata, {'foo' => 'Bar'}
assert_equal @object.metadata, {'foo' => 'Bar', 'spam' => 'peanutbutter'}

This comment has been minimized.

Copy link
@minter

minter Jul 29, 2011

I like peanut butter.

This comment has been minimized.

Copy link
@slyphon

slyphon via email Jul 29, 2011

Author Owner
end

def test_write_succeeds
Expand Down

0 comments on commit 1d3d3f0

Please sign in to comment.