1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Ensure values are strings before calling gsub

This commit is contained in:
Mike Virata-Stone 2016-08-11 21:57:12 -07:00
parent 5821baebe5
commit 20afe71f5f
2 changed files with 9 additions and 1 deletions

View file

@ -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

View file

@ -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)