aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBradley Harris <bharris@sermo.com>2011-04-29 14:47:49 -0400
committerBradley Harris <bharris@sermo.com>2011-04-29 14:47:49 -0400
commitaba149d702e4dcd999ce1b71688ec15b0c637875 (patch)
treee54a345b51d7469c747e4315874477565f77ee0f
parent245017765644745b0e550ceaf815ea4e73a12681 (diff)
downloadrails-aba149d702e4dcd999ce1b71688ec15b0c637875.tar.gz
rails-aba149d702e4dcd999ce1b71688ec15b0c637875.tar.bz2
rails-aba149d702e4dcd999ce1b71688ec15b0c637875.zip
Fix bug with empty CDATA not being handled in Hash.from_xml
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb3
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb4
2 files changed, 4 insertions, 3 deletions
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 = "<content><![CDATA[]]></content>"
+ xml = "<data><![CDATA[]]></data>"
- assert_equal "", Hash.from_xml(xml)["content"]
+ assert_equal "", Hash.from_xml(xml)["data"]
end
def test_xsd_like_types_from_xml