diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 2a34874..51eeaf9 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -53,6 +53,15 @@ class Hash "string" => Proc.new { |string| string.to_s }, "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml }, "base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) }, + "binary" => Proc.new do |bin, entity| + case entity['encoding'] + when 'base64' + ActiveSupport::Base64.decode64(bin) + # TODO: Add support for other encodings + else + bin + end + end, "file" => Proc.new do |file, entity| f = StringIO.new(ActiveSupport::Base64.decode64(file)) f.extend(FileLike) diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index ece5466..2edaea6 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -745,6 +745,7 @@ class HashToXmlTest < Test::Unit::TestCase 2007-12-25T12:34:56+0000 YmFiZS5wbmc= + VGhhdCdsbCBkbywgcGlnLg== EOT @@ -754,7 +755,8 @@ class HashToXmlTest < Test::Unit::TestCase :price => BigDecimal("12.50"), :expires_at => Time.utc(2007,12,25,12,34,56), :notes => "", - :illustration => "babe.png" + :illustration => "babe.png", + :caption => "That'll do, pig." }.stringify_keys assert_equal expected_bacon_hash, Hash.from_xml(bacon_xml)["bacon"]