Permalink
Browse files

Merge pull request #349 from bradley178/master

Hash.from_xml chokes on empty CDATA
  • Loading branch information...
2 parents c515f64 + aba149d commit a6ef255ff57519c174c87f45cb4c1d040050a364 @josevalim josevalim committed May 7, 2011
@@ -108,7 +108,8 @@ def typecast_xml_value(value)
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 @@ def test_tag_with_attrs_and_whitespace
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 @@ def test_type_trickles_through_when_unknown
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]

0 comments on commit a6ef255

Please sign in to comment.