Permalink
Browse files

Fix error when assigning NaN to an integer column

Also covers any non-castable case by returning nil, which
is in-line with the intention of the former implementation,
but covers the odd cases which respond to to_i but raise
an error when it's called, such as NaN, Infinity and -Infinity.

Fixes #8757

Backport of #8781

Cherry Pick of c147dd7
  • Loading branch information...
1 parent 335c988 commit 83c3475dd959d025d7f92cd7f9181cbc6fcc4a83 @trisweb trisweb committed with Chris Hooks Jan 6, 2013
@@ -175,7 +175,7 @@ def value_to_integer(value)
when TrueClass, FalseClass
value ? 1 : 0
else
- value.to_i
+ value.to_i rescue nil
end
end
@@ -48,6 +48,12 @@ def test_type_cast_non_integer_to_integer
column.type_cast(Object.new)
end
end
+
+ def test_type_cast_nan_and_infinity_to_integer
+ column = Column.new("field", nil, "integer")
+ assert_nil column.type_cast(Float::NAN)
+ assert_nil column.type_cast(1.0/0.0)
+ end
end
end
end

0 comments on commit 83c3475

Please sign in to comment.