From 245017765644745b0e550ceaf815ea4e73a12681 Mon Sep 17 00:00:00 2001 From: Bradley Harris Date: Fri, 29 Apr 2011 14:09:06 -0400 Subject: Added test for empty CDATA bug in from_xml --- activesupport/test/core_ext/hash_ext_test.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 012b956d7f..20b1362bcf 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -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 = "" + + assert_equal "", Hash.from_xml(xml)["content"] + end + def test_xsd_like_types_from_xml bacon_xml = <<-EOT @@ -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] -- cgit v1.2.3 From aba149d702e4dcd999ce1b71688ec15b0c637875 Mon Sep 17 00:00:00 2001 From: Bradley Harris Date: Fri, 29 Apr 2011 14:47:49 -0400 Subject: Fix bug with empty CDATA not being handled in Hash.from_xml --- activesupport/lib/active_support/core_ext/hash/conversions.rb | 3 ++- activesupport/test/core_ext/hash_ext_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 61a1d88b0e..102378a029 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -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) diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 20b1362bcf..3ef080e1cb 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -899,9 +899,9 @@ class HashToXmlTest < Test::Unit::TestCase end def test_empty_cdata_from_xml - xml = "" + xml = "" - assert_equal "", Hash.from_xml(xml)["content"] + assert_equal "", Hash.from_xml(xml)["data"] end def test_xsd_like_types_from_xml -- cgit v1.2.3