From d039b404421d7a9c8da303af3a91cf645841d7b3 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Wed, 27 Jan 2010 11:33:25 +0700 Subject: [PATCH] Modify the behavior of `radio_button_tag` to use `sanitize_to_id` for consistency --- .../lib/action_view/helpers/form_tag_helper.rb | 4 +--- actionpack/test/template/form_tag_helper_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index eaba603..5c6034d 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -312,9 +312,7 @@ module ActionView # radio_button_tag 'color', "green", true, :class => "color_input" # # => def radio_button_tag(name, value, checked = false, options = {}) - pretty_tag_value = value.to_s.gsub(/\s/, "_").gsub(/(?!-)\W/, "").downcase - pretty_name = name.to_s.gsub(/\[/, "_").gsub(/\]/, "") - html_options = { "type" => "radio", "name" => name, "id" => "#{pretty_name}_#{pretty_tag_value}", "value" => value }.update(options.stringify_keys) + html_options = { "type" => "radio", "name" => name, "id" => "#{sanitize_to_id(name)}_#{sanitize_to_id(value)}", "value" => value }.update(options.stringify_keys) html_options["checked"] = "checked" if checked tag :input, html_options end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 09a0c64..803cf79 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -110,6 +110,10 @@ class FormTagHelperTest < ActionView::TestCase actual = radio_button_tag("person[gender]", "m") expected = %() assert_dom_equal expected, actual + + actual = radio_button_tag('ctrlname', 'apache2.2') + expected = %() + assert_dom_equal expected, actual end def test_select_tag -- 1.6.4.2