Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit aa48c79ae41e34825b79eb753d61bb8157271a94 1 parent 1668ad3
@jeremy jeremy authored
View
3  actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -78,6 +78,9 @@ def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)
# # <option>Paris</option><option>Rome</option></select>
def select_tag(name, option_tags = nil, options = {})
html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name
+ 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
content_tag :select, option_tags, { "name" => html_name, "id" => sanitize_to_id(name) }.update(options.stringify_keys)
end
View
6 actionpack/test/template/form_tag_helper_test.rb
@@ -135,6 +135,12 @@ def test_select_tag_id_sanitized
assert_match VALID_HTML_ID, input_elem['id']
end
+ def test_select_tag_with_array_options
+ assert_deprecated /array/ do
+ select_tag "people", ["<option>david</option>"]
+ end
+ end
+
def test_text_area_tag_size_string
actual = text_area_tag "body", "hello world", "size" => "20x40"
expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
Please sign in to comment.
Something went wrong with that request. Please try again.