Skip to content
This repository
Browse code

Merge pull request #2036 from Bodacious/tag_helper_data_fix

TagHelper creates invalid data attributes when value is a BigDecimal
  • Loading branch information...
commit 319903bde56bae0f7c83a049bb44377522699bd8 2 parents 8067857 + 56aabfd
Rafael Mendonça França rafaelfranca authored
5 actionpack/lib/action_view/helpers/tag_helper.rb
@@ -154,8 +154,9 @@ def tag_options(options, escape = true)
154 154
155 155 def data_tag_option(key, value, escape)
156 156 key = "data-#{key.to_s.dasherize}"
157   - value = value.to_json if !value.is_a?(String) && !value.is_a?(Symbol)
158   -
  157 + unless value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(BigDecimal)
  158 + value = value.to_json
  159 + end
159 160 tag_option(key, value, escape)
160 161 end
161 162
4 actionpack/test/template/tag_helper_test.rb
@@ -118,8 +118,8 @@ def test_disable_escaping
118 118
119 119 def test_data_attributes
120 120 ['data', :data].each { |data|
121   - assert_dom_equal '<a data-a-number="1" data-array="[1,2,3]" data-hash="{&quot;key&quot;:&quot;value&quot;}" data-string="hello" data-symbol="foo" />',
122   - tag('a', { data => { :a_number => 1, :string => 'hello', :symbol => :foo, :array => [1, 2, 3], :hash => { :key => 'value'} } })
  121 + assert_dom_equal '<a data-a-float="3.14" data-a-big-decimal="-123.456" data-a-number="1" data-array="[1,2,3]" data-hash="{&quot;key&quot;:&quot;value&quot;}" data-string="hello" data-symbol="foo" />',
  122 + tag('a', { data => { :a_float => 3.14, :a_big_decimal => BigDecimal.new("-123.456"), :a_number => 1, :string => 'hello', :symbol => :foo, :array => [1, 2, 3], :hash => { :key => 'value'} } })
123 123 }
124 124 end
125 125 end

0 comments on commit 319903b

Please sign in to comment.
Something went wrong with that request. Please try again.