diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-04 16:47:35 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-04 16:47:35 -0700 |
commit | 58950ee224e8d81cb8bd79edb4a2f0fb7ca75b68 (patch) | |
tree | 36416b1e373352122bb7f6e03186afe37d5153aa /activerecord | |
parent | d5cc7113076ccd82b6e7582ce77fd2062323c87d (diff) | |
parent | 06c23c4c7ff842f7c6237f3ac43fc9d19509a947 (diff) | |
download | rails-58950ee224e8d81cb8bd79edb4a2f0fb7ca75b68.tar.gz rails-58950ee224e8d81cb8bd79edb4a2f0fb7ca75b68.tar.bz2 rails-58950ee224e8d81cb8bd79edb4a2f0fb7ca75b68.zip |
Merge pull request #3713 from kf8a/master
postgresql adapter should quote not a number and infinity correctly for float columns
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/quoting_test.rb | 12 |
2 files changed, 19 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 68cf495025..4d5459939b 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -511,8 +511,13 @@ module ActiveRecord else super end 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. diff --git a/activerecord/test/cases/adapters/postgresql/quoting_test.rb b/activerecord/test/cases/adapters/postgresql/quoting_test.rb index 172055f15c..f8a605b67c 100644 --- a/activerecord/test/cases/adapters/postgresql/quoting_test.rb +++ b/activerecord/test/cases/adapters/postgresql/quoting_test.rb @@ -19,6 +19,18 @@ module ActiveRecord 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 |