Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure option_html_attributes does not modify the given option hashes

We can avoid creating extra hashes with #merge, and use #merge! instead.
  • Loading branch information...
commit a513cc1862cc61fd9605352a58c5e36cc40cb574 1 parent e8e8617
Carlos Antonio da Silva carlosantoniodasilva authored
2  actionpack/lib/action_view/helpers/form_options_helper.rb
View
@@ -709,7 +709,7 @@ def collection_check_boxes(object, method, collection, value_method, text_method
private
def option_html_attributes(element)
if Array === element
- element.select { |e| Hash === e }.reduce({}, :merge)
+ element.select { |e| Hash === e }.reduce({}, :merge!)
else
{}
end
9 actionpack/test/template/form_options_helper_test.rb
View
@@ -1193,6 +1193,15 @@ def test_option_html_attributes_with_multiple_hashes
)
end
+ def test_option_html_attributes_with_multiple_hashes_does_not_modify_them
+ options1 = { class: 'fancy' }
+ options2 = { onclick: "alert('Hello World');" }
+ option_html_attributes([ 'foo', 'bar', options1, options2 ])
+
+ assert_equal({ class: 'fancy' }, options1)
+ assert_equal({ onclick: "alert('Hello World');" }, options2)
+ end
+
def test_grouped_collection_select
@post = Post.new
@post.origin = 'dk'
Please sign in to comment.
Something went wrong with that request. Please try again.