Skip to content

Commit ebe8dd6

Browse files
codebruleeNZKoz
authored andcommitted
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
1 parent 17e712d commit ebe8dd6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

activesupport/lib/active_support/core_ext/hash/conversions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def unrename_keys(params)
221221
case params.class.to_s
222222
when "Hash"
223223
params.inject({}) do |h,(k,v)|
224-
h[k.to_s.underscore.tr("-", "_")] = unrename_keys(v)
224+
h[k.to_s.tr("-", "_")] = unrename_keys(v)
225225
h
226226
end
227227
when "Array"

activesupport/test/core_ext/hash_ext_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,22 @@ def test_empty_array_from_xml
654654
assert_equal expected_blog_hash, Hash.from_xml(blog_xml)
655655
end
656656

657+
def test_all_caps_key_from_xml
658+
test_xml = <<-EOT
659+
<ABC3XYZ>
660+
<TEST>Lorem Ipsum</TEST>
661+
</ABC3XYZ>
662+
EOT
663+
664+
expected_hash = {
665+
"ABC3XYZ" => {
666+
"TEST" => "Lorem Ipsum"
667+
}
668+
}
669+
670+
assert_equal expected_hash, Hash.from_xml(test_xml)
671+
end
672+
657673
def test_empty_array_with_whitespace_from_xml
658674
blog_xml = <<-XML
659675
<blog>

0 commit comments

Comments
 (0)