mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Merge pull request #349 from bradley178/master
Hash.from_xml chokes on empty CDATA
This commit is contained in:
@@ -108,7 +108,8 @@ class Hash
|
||||
raise "can't typecast #{entries.inspect}"
|
||||
end
|
||||
end
|
||||
elsif value['type'] == 'file' || value["__content__"].present?
|
||||
elsif value['type'] == 'file' ||
|
||||
(value["__content__"] && (value.keys.size == 1 || value["__content__"].present?))
|
||||
content = value["__content__"]
|
||||
if parser = ActiveSupport::XmlMini::PARSING[value["type"]]
|
||||
parser.arity == 1 ? parser.call(content) : parser.call(content, value)
|
||||
|
||||
@@ -897,7 +897,13 @@ class HashToXmlTest < Test::Unit::TestCase
|
||||
hash = Hash.from_xml(xml)
|
||||
assert_equal "bacon is the best", hash['blog']['name']
|
||||
end
|
||||
|
||||
|
||||
def test_empty_cdata_from_xml
|
||||
xml = "<data><![CDATA[]]></data>"
|
||||
|
||||
assert_equal "", Hash.from_xml(xml)["data"]
|
||||
end
|
||||
|
||||
def test_xsd_like_types_from_xml
|
||||
bacon_xml = <<-EOT
|
||||
<bacon>
|
||||
@@ -940,7 +946,7 @@ class HashToXmlTest < Test::Unit::TestCase
|
||||
|
||||
assert_equal expected_product_hash, Hash.from_xml(product_xml)["product"]
|
||||
end
|
||||
|
||||
|
||||
def test_should_use_default_value_for_unknown_key
|
||||
hash_wia = HashWithIndifferentAccess.new(3)
|
||||
assert_equal 3, hash_wia[:new_key]
|
||||
|
||||
Reference in New Issue
Block a user