Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #26131 from smellsblue/dont-fail-on-non-string
Browse files Browse the repository at this point in the history
Remove dead code and ensure values are strings before calling gsub
  • Loading branch information
rafaelfranca committed Aug 12, 2016
2 parents fecc67d + efd59ab commit 64d5785
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions actionpack/lib/action_view/helpers/tag_helper.rb
Expand Up @@ -147,7 +147,6 @@ def tag_options(options, escape = true)
elsif BOOLEAN_ATTRIBUTES.include?(key)
attrs << %(#{key}="#{key}") if value
elsif !value.nil?
final_value = value.is_a?(Array) ? value.join(" ") : value
attrs << tag_option(key, value, escape)
end
end
Expand All @@ -159,7 +158,7 @@ def tag_option(key, value, escape)
if value.is_a?(Array)
value = escape ? safe_join(value, " ") : value.join(" ")
else
value = escape ? ERB::Util.html_escape(value) : value
value = escape ? ERB::Util.html_escape(value) : value.to_s
end
%(#{key}="#{value.gsub(/"/, '&quot;'.freeze)}")
end
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/template/tag_helper_test.rb
Expand Up @@ -29,6 +29,14 @@ def test_tag_options_accepts_blank_option
assert_equal "<p included=\"\" />", 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_equal '<p disabled="disabled" multiple="multiple" readonly="readonly" />',
tag("p", :disabled => true, :multiple => true, :readonly => true)
Expand Down

0 comments on commit 64d5785

Please sign in to comment.