Skip to content

Commit 39b9c94

Browse files
committed
Fixed tag_helper data-attribute bug with BigDecimals
1 parent 6ef9fda commit 39b9c94

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

actionpack/lib/action_view/helpers/tag_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def tag_options(options, escape = true)
138138
options.each_pair do |key, value|
139139
if key.to_s == 'data' && value.is_a?(Hash)
140140
value.each do |k, v|
141-
if !v.is_a?(String) && !v.is_a?(Symbol)
141+
unless v.is_a?(String) || v.is_a?(Symbol) || v.is_a?(BigDecimal)
142142
v = v.to_json
143143
end
144144
v = ERB::Util.html_escape(v) if escape

actionpack/test/template/tag_helper_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def test_disable_escaping
113113

114114
def test_data_attributes
115115
['data', :data].each { |data|
116-
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" />',
117-
tag('a', { data => { :a_number => 1, :string => 'hello', :symbol => :foo, :array => [1, 2, 3], :hash => { :key => 'value'} } })
116+
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" />',
117+
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'} } })
118118
}
119119
end
120120
end

0 commit comments

Comments
 (0)