diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 402afa237ff8180c9206bf6ab58a971b3f8150a5..432780a94e364f670377ffa9ecaca375da14f54b 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Hash#to_xml handles keys with the same name as Kernel methods. #6613 [Catfish] + * Added Time#end_of_day to get 23:59:59 of that day [DHH] * Don't quote hash keys in Hash#to_json if they're valid JavaScript identifiers. Disable this with ActiveSupport::JSON.unquote_hash_key_identifiers = false if you need strict JSON compliance. [Sam Stephenson] diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 65047b2d3c86c5213212416bd8bbe4989e9f3e0a..83054cde936544ccbc94df2db322bad978387bd4 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -35,7 +35,7 @@ def to_xml(options = {}) dasherize = !options.has_key?(:dasherize) || options[:dasherize] root = dasherize ? options[:root].to_s.dasherize : options[:root].to_s - options[:builder].__send__(root) do + options[:builder].__send__(:method_missing, root) do each do |key, value| case value when ::Hash diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 020e383c1a1fa3b3a65548b757e1da697040cd7d..3ede4893a5785567977c63193e4f20e8641f44a3 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -458,4 +458,15 @@ def test_should_copy_the_default_value_when_converting_to_hash_with_indifferent_ hash_wia = hash.with_indifferent_access assert_equal 3, hash_wia.default end + + # The XML builder seems to fail miserably when trying to tag something + # with the same name as a Kernel method (throw, test, loop, select ...) + def test_kernel_method_names_to_xml + hash = { :throw => { :ball => 'red' } } + expected = 'red' + + assert_nothing_raised do + assert_equal expected, hash.to_xml(@xml_options) + end + end end