From ebe8dd6108ab9b2ecd74bacf7fa128e9d4f28e4e Mon Sep 17 00:00:00 2001 From: codebrulee Date: Mon, 4 May 2009 09:51:35 -0700 Subject: [PATCH] Remove stray underscore from the hash conversion methods which broke backwards compatibility with Hash.from_xml Also add an all-caps test to prevent future regressions --- .../active_support/core_ext/hash/conversions.rb | 2 +- activesupport/test/core_ext/hash_ext_test.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 10435975c53d..37d035ecf26f 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -221,7 +221,7 @@ def unrename_keys(params) case params.class.to_s when "Hash" params.inject({}) do |h,(k,v)| - h[k.to_s.underscore.tr("-", "_")] = unrename_keys(v) + h[k.to_s.tr("-", "_")] = unrename_keys(v) h end when "Array" diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 0edac72fe7ba..31519a1654ae 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -654,6 +654,22 @@ def test_empty_array_from_xml assert_equal expected_blog_hash, Hash.from_xml(blog_xml) end + def test_all_caps_key_from_xml + test_xml = <<-EOT + + Lorem Ipsum + + EOT + + expected_hash = { + "ABC3XYZ" => { + "TEST" => "Lorem Ipsum" + } + } + + assert_equal expected_hash, Hash.from_xml(test_xml) + end + def test_empty_array_with_whitespace_from_xml blog_xml = <<-XML