diff options
author | Andre Arko <andre@arko.net> | 2011-04-14 16:25:08 +0800 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2011-04-14 16:33:41 +0800 |
commit | 7660e7cb4df69ad127661ad87f495a3b212170b9 (patch) | |
tree | f31be8968db5a9385eeccda24476d66338acfdd7 | |
parent | ada550d9088be9845ff8e4dbe0f27e574c5fc62b (diff) | |
download | rails-7660e7cb4df69ad127661ad87f495a3b212170b9.tar.gz rails-7660e7cb4df69ad127661ad87f495a3b212170b9.tar.bz2 rails-7660e7cb4df69ad127661ad87f495a3b212170b9.zip |
attributes no longer disappear if a tag contains whitespace
old:
Hash.from_xml("<tag foo='bar'>\n</tag>")
=> {"tag"=>"\n"}
new:
Hash.from_xml("<tag foo='bar'>\n</tag>")
=> {"tag"=>{"foo"=>"bar", "__content__"=>"\n"}
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/conversions.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 3005fef44c..06bd8341ca 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -108,7 +108,7 @@ class Hash raise "can't typecast #{entries.inspect}" end end - elsif value.has_key?("__content__") + elsif value.has_key?("__content__") && value["__content__"].gsub(/\s/, '').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 a0479d45ac..012b956d7f 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -889,6 +889,15 @@ class HashToXmlTest < Test::Unit::TestCase assert_equal 'application/octet-stream', file.content_type end + def test_tag_with_attrs_and_whitespace + xml = <<-XML + <blog name="bacon is the best"> + </blog> + XML + hash = Hash.from_xml(xml) + assert_equal "bacon is the best", hash['blog']['name'] + end + def test_xsd_like_types_from_xml bacon_xml = <<-EOT <bacon> |