Skip to content

Commit

Permalink
Hash#to_xml handles keys with the same name as Kernel methods. Closes #…
Browse files Browse the repository at this point in the history
…6613.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5521 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Nov 14, 2006
1 parent 50ee332 commit b97ffa2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions 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]
Expand Down
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions activesupport/test/core_ext/hash_ext_test.rb
Expand Up @@ -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 = '<person><throw><ball>red</ball></throw></person>'

assert_nothing_raised do
assert_equal expected, hash.to_xml(@xml_options)
end
end
end

0 comments on commit b97ffa2

Please sign in to comment.