aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorInnokenty Mihailov <anotheroneman@yahoo.com>2013-12-18 23:12:53 +0200
committerYves Senn <yves.senn@gmail.com>2014-05-12 15:46:48 +0200
commitaac40bcc07b3defb2134b2c08a88e197c469a702 (patch)
treea6827aa7581fc6aca840fa646a35bc3afe33c055 /activerecord/lib/active_record
parentf25f5336ee07cc42207dc036d1a962b500969d10 (diff)
downloadrails-aac40bcc07b3defb2134b2c08a88e197c469a702.tar.gz
rails-aac40bcc07b3defb2134b2c08a88e197c469a702.tar.bz2
rails-aac40bcc07b3defb2134b2c08a88e197c469a702.zip
pg, fix Infinity and NaN values conversion.
Before this patch `Infinity`, `-Infinity` and `Nan` were read as `0`.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
index 540b3694b5..14beb7bd25 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
@@ -249,9 +249,14 @@ This is not reliable and will be removed in the future.
def type; :float end
def type_cast(value)
- return if value.nil?
-
- value.to_f
+ case value
+ when nil; nil
+ when 'Infinity'; ::Float::INFINITY
+ when '-Infinity'; -::Float::INFINITY
+ when 'NaN'; ::Float::NAN
+ else
+ value.to_f
+ end
end
end