aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-08-02 12:05:01 -0400
committerGitHub <noreply@github.com>2017-08-02 12:05:01 -0400
commit5fd50c387bdfc2761859ec7a57477bcd56e93210 (patch)
treeb2357bb90e5e99ed217a4e92feba4908760de139
parent869cb93de12141425b73f43e93f6e3730147b0ed (diff)
parentd656097734928e1f6b3c3bd884e128c4e299f2ec (diff)
downloadrails-5fd50c387bdfc2761859ec7a57477bcd56e93210.tar.gz
rails-5fd50c387bdfc2761859ec7a57477bcd56e93210.tar.bz2
rails-5fd50c387bdfc2761859ec7a57477bcd56e93210.zip
Merge pull request #29984 from colorfulfool/form-helpers-unicode-sanitization
Allow non-English values for collection_radio_buttons
-rw-r--r--actionview/lib/action_view/helpers/tags/base.rb2
-rw-r--r--actionview/test/template/form_collections_helper_test.rb14
2 files changed, 15 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/tags/base.rb b/actionview/lib/action_view/helpers/tags/base.rb
index bbb8c4d224..922d4c5390 100644
--- a/actionview/lib/action_view/helpers/tags/base.rb
+++ b/actionview/lib/action_view/helpers/tags/base.rb
@@ -138,7 +138,7 @@ module ActionView
end
def sanitized_value(value)
- value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase
+ value.to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase.to_s
end
def select_content_tag(option_tags, options, html_options)
diff --git a/actionview/test/template/form_collections_helper_test.rb b/actionview/test/template/form_collections_helper_test.rb
index aa72621c7d..bba529a98a 100644
--- a/actionview/test/template/form_collections_helper_test.rb
+++ b/actionview/test/template/form_collections_helper_test.rb
@@ -39,6 +39,13 @@ class FormCollectionsHelperTest < ActionView::TestCase
assert_select "label[for=user_active_no]", "No"
end
+ test "collection radio generates labels for non-English values correctly" do
+ with_collection_radio_buttons :user, :title, ["Господин", "Госпожа"], :to_s, :to_s
+
+ assert_select "input[type=radio]#user_title_господин"
+ assert_select "label[for=user_title_господин]", "Господин"
+ end
+
test "collection radio should sanitize collection values for labels correctly" do
with_collection_radio_buttons :user, :name, ["$0.99", "$1.99"], :to_s, :to_s
assert_select "label[for=user_name_099]", "$0.99"
@@ -299,6 +306,13 @@ class FormCollectionsHelperTest < ActionView::TestCase
assert_select "label[for=user_name_199]", "$1.99"
end
+ test "collection check boxes generates labels for non-English values correctly" do
+ with_collection_check_boxes :user, :title, ["Господин", "Госпожа"], :to_s, :to_s
+
+ assert_select "input[type=checkbox]#user_title_господин"
+ assert_select "label[for=user_title_господин]", "Господин"
+ end
+
test "collection check boxes accepts html options as the last element of array" do
collection = [[1, "Category 1", { class: "foo" }], [2, "Category 2", { class: "bar" }]]
with_collection_check_boxes :user, :active, collection, :first, :second