mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #3713 from kf8a/master
postgresql adapter should quote not a number and infinity correctly for float columns
This commit is contained in:
commit
58950ee224
2 changed files with 19 additions and 2 deletions
|
@ -511,8 +511,13 @@ module ActiveRecord
|
||||||
else super
|
else super
|
||||||
end
|
end
|
||||||
when Float
|
when Float
|
||||||
return super unless value.infinite? && column.type == :datetime
|
if value.infinite? && column.type == :datetime
|
||||||
"'#{value.to_s.downcase}'"
|
"'#{value.to_s.downcase}'"
|
||||||
|
elsif value.infinite? || value.nan?
|
||||||
|
"'#{value.to_s}'"
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
when Numeric
|
when Numeric
|
||||||
return super unless column.sql_type == 'money'
|
return super unless column.sql_type == 'money'
|
||||||
# Not truly string input, so doesn't require (or allow) escape string syntax.
|
# Not truly string input, so doesn't require (or allow) escape string syntax.
|
||||||
|
|
|
@ -19,6 +19,18 @@ module ActiveRecord
|
||||||
assert_equal 'f', @conn.type_cast(false, nil)
|
assert_equal 'f', @conn.type_cast(false, nil)
|
||||||
assert_equal 'f', @conn.type_cast(false, c)
|
assert_equal 'f', @conn.type_cast(false, c)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_quote_float_nan
|
||||||
|
nan = 0.0/0
|
||||||
|
c = Column.new(nil, 1, 'float')
|
||||||
|
assert_equal "'NaN'", @conn.quote(nan, c)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_quote_float_infinity
|
||||||
|
infinity = 1.0/0
|
||||||
|
c = Column.new(nil, 1, 'float')
|
||||||
|
assert_equal "'Infinity'", @conn.quote(infinity, c)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue