This project is archived and is in readonly mode.
Hash.from_xml fieldnames uncamelizing
Reported by Gregg Kellogg | March 25th, 2009 @ 07:19 AM | in 3.x
Calling Hash.from_xml with CamelCase element and attribute names causes the names to be underscored.
From http://www.bluequartz.us/phpBB2/...
xml = %(<blah_blah> 1 2 <dasherized_tag> 3 </dasherized_tag> </blah_blah>)
h = Hash.from_xml(xml)
assert_equal(h, {"blah_blah" => {"JunkOne" => "1", "JunkTwo" => "2", "dasherized_tag" => "3"}})
notice that regardless of the tag name the key is the same string. what rails is currently doing is giving me a result that looks like this: {"blah_blah" => {"junk_one" => "1", "junk_two" => "2", "dasherized_tag" => "3"}}
The bug results from a change to ActiveSupport::CoreExtensions::Hash::Conversions::ClassMethods::unrename_keys which used to be:
h[k.to_s.tr("-", "_")] = unrename_keys(v)
Comments and changes to this ticket
-
marktucks March 26th, 2009 @ 09:02 PM
I tried this in script/console and got the following output?
xml = %(<blah_blah> 1 2 <dasherized_tag> 3 </dasherized_tag> </blah_blah>) => "<blah_blah> 1 2 <dasherized_tag> 3 </dasherized_tag> </blah_blah>" h = Hash.from_xml(xml) => {"blah_blah"=>" 1 2 "}
It doesn't seem to have the Junk entries and has removed the <dasherized_tag>s
-
marktucks March 26th, 2009 @ 09:04 PM
Apologies for the formatting.
@@@ruby xml = %(<blah_blah> 1 2 <dasherized_tag> 3 </dasherized_tag> </blah_blah>) => "<blah_blah> 1 2 <dasherized_tag> 3 </dasherized_tag> </blah_blah>" h = Hash.from_xml(xml) => {"blah_blah"=>" 1 2 "}
-
Gregg Kellogg March 26th, 2009 @ 11:15 PM
It would probably help if i used the whole test string:
xml = %(<blah_blah> 1 2 <dasherized_tag> 3 </dasherized_tag> </blah_blah>)
-
Gregg Kellogg March 26th, 2009 @ 11:16 PM
Oops! It seems that it's getting eaten on the submit. I'll modify the appropriate unit test and upload it.
-
Gregg Kellogg March 26th, 2009 @ 11:19 PM
See if this works.
@@@ruby xml = %(<blah_blah> 1 2 <dasherized_tag> 3 </dasherized_tag> </blah_blah>)
-
Gregg Kellogg March 26th, 2009 @ 11:28 PM
Okay, here's an updated activesupport/test/core_ext/hash_ext_test.rb with new test test_single_record_from_xml_with_camel_case
-
Gregg Kellogg July 8th, 2009 @ 06:13 PM
- Assigned user set to Jeremy Kemper
Seems to have been fixed in commit eb201e64c0b68aee6d0715d44cf48178204c4133 "Fixed Hash#from_xml with keys that are all caps."
-
Denis October 14th, 2009 @ 05:52 PM
The constant changing of Hash#from_xml in re: camelCase tags is very confusing. I filed https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets..., mainly as a way to ask that the correct & intended behavior be documented (and then I'd be happy to add a unit test for it).
-
Mike Grafton December 6th, 2009 @ 06:15 PM
+1 for what Denis said. Also please see my comment on issue #3377
-
Ryan Bigg October 9th, 2010 @ 09:53 PM
- Tag cleared.
- Importance changed from to Low
Automatic cleanup of spam.
-
David Trasbo October 10th, 2010 @ 03:57 PM
- State changed from new to resolved
Fixed in http://github.com/rails/rails/commit/eb201e64c0b68aee6d0715d44cf481...
Further discussion regarding
Hash.from_xml
is referred to #3377.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 3377 Hash.from_xml converted camelCase to underscore in 2.3.2, doesn't in 2.3.4 In attempting to fix the all-caps tags bug, commit eb201...