Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure values are strings before calling gsub #26133

Merged
merged 1 commit into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def tag_option(key, value, escape)
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
Expand Down
8 changes: 8 additions & 0 deletions actionview/test/template/tag_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ def test_tag_builder_options_accepts_blank_option
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)
Expand Down