Merge pull request #36981 from tsuka/fix-tag-builder

Prevent TagBuilder modify options
This commit is contained in:
Rafael França 2019-08-19 14:06:11 -04:00 committed by GitHub
commit 4df0563dc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

@ -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.to_s.dup
value = escape ? ERB::Util.unwrapped_html_escape(value).dup : value.to_s.dup
end
value.gsub!('"', """)
%(#{key}="#{value}")

@ -79,6 +79,13 @@ def test_tag_builder_options_converts_boolean_option
tag.p(disabled: true, itemscope: true, multiple: true, readonly: true, allowfullscreen: true, seamless: true, typemustmatch: true, sortable: true, default: true, inert: true, truespeed: true)
end
def test_tag_builder_do_not_modify_html_safe_options
html_safe_str = '"'.html_safe
assert_equal "<p value=\"&quot;\" />", tag("p", value: html_safe_str)
assert_equal '"', html_safe_str
assert html_safe_str.html_safe?
end
def test_content_tag
assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
assert_predicate content_tag("a", "Create", "href" => "create"), :html_safe?