Browse files

postgresql adapter handles quoting of not a number (NaN) and Infinity

  • Loading branch information...
1 parent 5d704fa commit 06c23c4c7ff842f7c6237f3ac43fc9d19509a947 @kf8a kf8a committed Nov 21, 2011
View
9 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -415,8 +415,13 @@ def quote(value, column = nil) #:nodoc:
case value
when Float
- return super unless value.infinite? && column.type == :datetime
- "'#{value.to_s.downcase}'"
+ if value.infinite? && column.type == :datetime
+ "'#{value.to_s.downcase}'"
+ elsif value.infinite? || value.nan?
+ "'#{value.to_s}'"
+ else
+ super
+ end
when Numeric
return super unless column.sql_type == 'money'
# Not truly string input, so doesn't require (or allow) escape string syntax.
View
12 activerecord/test/cases/adapters/postgresql/quoting_test.rb
@@ -19,6 +19,18 @@ def test_type_cast_false
assert_equal 'f', @conn.type_cast(false, nil)
assert_equal 'f', @conn.type_cast(false, c)
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

0 comments on commit 06c23c4

Please sign in to comment.