diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2016-11-13 14:46:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-13 14:46:21 +0000 |
commit | c85d305a67f83f3a92488a641654b85b90b8747a (patch) | |
tree | accd26754b8b42edf697a44c857359ae421ac5c9 /activesupport/test/json | |
parent | df63abe6d31cdbe426ff6dda9bdd878acc602728 (diff) | |
parent | 8776f15b448ed88b1108e70f2de22f0b599818aa (diff) | |
download | rails-c85d305a67f83f3a92488a641654b85b90b8747a.tar.gz rails-c85d305a67f83f3a92488a641654b85b90b8747a.tar.bz2 rails-c85d305a67f83f3a92488a641654b85b90b8747a.zip |
Merge pull request #26933 from prathamesh-sonpatki/fix-26877
Fix an issue with JSON encoding of "Infinity" and "NaN" values
Diffstat (limited to 'activesupport/test/json')
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index fc3af02cbc..e745f5e190 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -432,6 +432,28 @@ EXPECTED assert_equal '"foo"', ActiveSupport::JSON.encode(exception) end + class InfiniteNumber + def as_json(options = nil) + { "number" => 1.0 / 0 } + end + end + + def test_to_json_works_when_as_json_returns_infinite_number + expected = { number: nil }.to_json + assert_equal expected, InfiniteNumber.new.to_json + end + + class NaNNumber + def as_json(options = nil) + { "number" => 0.0 / 0 } + end + end + + def test_to_json_works_when_as_json_returns_NaN_number + expected = { number: nil }.to_json + assert_equal expected, NaNNumber.new.to_json + end + protected def object_keys(json_object) |