Permalink
Browse files

Fix bug with empty CDATA not being handled in Hash.from_xml

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent dc2b999 commit 849007f743f1ba0bce02f8c4650a2ceb5b70f394 Bradley Harris committed with josevalim Apr 29, 2011
@@ -96,7 +96,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)
@@ -865,7 +865,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>

0 comments on commit 849007f

Please sign in to comment.