rails / rails

Ruby on Rails
https://rubyonrails.org
MIT License
55.8k stars 21.6k forks source link

Radio button value sanitizing differs between FormTagHelper#radio_button_tag and FormBuilder#radio_button #37634

Closed graywh closed 4 years ago

graywh commented 4 years ago

I was re-writing my custom radio button array builder to bypass #field_error_proc and realized that the generated input ids were different, which affected all references to these inputs in JavaScript.

This is caused by having two different functions to sanitize the radio button value.

FormTagHelper#radio_button_tag uses FormTagHelper#sanitize_to_id

https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/form_tag_helper.rb#L894

def sanitize_to_id(name)
  name.to_s.delete("]").tr("^-a-zA-Z0-9:.", "_")
end

while FormBuilder#radio_button uses Tags::Base#sanitized_value

https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/tags/base.rb#L139

def sanitized_value(value)
  value.to_s.gsub(/[\s\.]/, "_").gsub(/[^-[[:word:]]]/, "").downcase
end
rails-bot[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not been commented on for at least three months. The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the 6-0-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open. Thank you for all your contributions.