提交 c7cc9583 编写于 作者: J Josh Franklin 提交者: José Valim

Add support for a type=binary with an optional encoding=base64. If the...

Add support for a type=binary with an optional encoding=base64. If the encoding attribute is absent, the data is considered unencoded.
[#2966 state:resolved]
上级 4c7c4061
......@@ -54,6 +54,15 @@ def content_type
"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)
......
......@@ -757,6 +757,7 @@ def test_xsd_like_types_from_xml
<expires-at type="dateTime">2007-12-25T12:34:56+0000</expires-at>
<notes type="string"></notes>
<illustration type="base64Binary">YmFiZS5wbmc=</illustration>
<caption type="binary" encoding="base64">VGhhdCdsbCBkbywgcGlnLg==</caption>
</bacon>
EOT
......@@ -766,7 +767,8 @@ def test_xsd_like_types_from_xml
: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"]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册