diff options
author | Mike Virata-Stone <mjstone@on-site.com> | 2016-08-11 21:57:12 -0700 |
---|---|---|
committer | Mike Virata-Stone <mjstone@on-site.com> | 2016-08-12 00:02:13 -0700 |
commit | 20afe71f5f63ad07b99e7257539fffd0da817e83 (patch) | |
tree | 84aaacf6ff61b9ed66ca5b181d1444a7b58d2764 | |
parent | 5821baebe5cedf710ffa5bd99ff80b2150227676 (diff) | |
download | rails-20afe71f5f63ad07b99e7257539fffd0da817e83.tar.gz rails-20afe71f5f63ad07b99e7257539fffd0da817e83.tar.bz2 rails-20afe71f5f63ad07b99e7257539fffd0da817e83.zip |
Ensure values are strings before calling gsub
-rw-r--r-- | actionview/lib/action_view/helpers/tag_helper.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/tag_helper_test.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb index 7af26edf95..4950f272a4 100644 --- a/actionview/lib/action_view/helpers/tag_helper.rb +++ b/actionview/lib/action_view/helpers/tag_helper.rb @@ -88,7 +88,7 @@ module ActionView if value.is_a?(Array) value = escape ? safe_join(value, " ") : value.join(" ") else - value = escape ? ERB::Util.unwrapped_html_escape(value) : value + value = escape ? ERB::Util.unwrapped_html_escape(value) : value.to_s end %(#{key}="#{value.gsub(/"/, '"'.freeze)}") end diff --git a/actionview/test/template/tag_helper_test.rb b/actionview/test/template/tag_helper_test.rb index c7c6649657..d07312ace3 100644 --- a/actionview/test/template/tag_helper_test.rb +++ b/actionview/test/template/tag_helper_test.rb @@ -59,6 +59,14 @@ class TagHelperTest < ActionView::TestCase assert_equal "<p included=\"\"></p>", tag.p(included: "") end + def test_tag_options_accepts_symbol_option_when_not_escaping + assert_equal "<p value=\"symbol\" />", tag("p", { value: :symbol }, false, false) + end + + def test_tag_options_accepts_integer_option_when_not_escaping + assert_equal "<p value=\"42\" />", tag("p", { value: 42 }, false, false) + end + def test_tag_options_converts_boolean_option assert_dom_equal '<p disabled="disabled" itemscope="itemscope" multiple="multiple" readonly="readonly" allowfullscreen="allowfullscreen" seamless="seamless" typemustmatch="typemustmatch" sortable="sortable" default="default" inert="inert" truespeed="truespeed" />', tag("p", disabled: true, itemscope: true, multiple: true, readonly: true, allowfullscreen: true, seamless: true, typemustmatch: true, sortable: true, default: true, inert: true, truespeed: true) |