From 3859828d89d378986af0fc2390608b00aad5e912 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 31 Mar 2010 19:49:29 -0700 Subject: HTML safety: give a deprecation warning if an array of option tags is passed to select tag. Be sure to join the tag yourself and mark them .html_safe --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 4 ++++ actionpack/test/template/form_tag_helper_test.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index ca100e102e..0d47c6eecb 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -93,6 +93,10 @@ module ActionView # # => def select_tag(name, option_tags = nil, options = {}) + if Array === option_tags + ActiveSupport::Deprecation.warn 'Passing an array of option_tags to select_tag implicitly joins them without marking them as HTML-safe. Pass option_tags.join.html_safe instead.', caller + end + html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name if blank = options.delete(:include_blank) if blank.kind_of?(String) diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 868a35c476..1f26840289 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -158,6 +158,12 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_select_tag_with_array_options + assert_deprecated /array/ do + select_tag "people", [""] + end + end + def test_text_area_tag_size_string actual = text_area_tag "body", "hello world", "size" => "20x40" expected = %() -- cgit v1.2.3