aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2012-04-30 21:06:22 -0700
committerPiotr Sarnacki <drogus@gmail.com>2012-04-30 21:06:22 -0700
commit3cc6995e714bc763b40eb3e1d710c1e5ded44384 (patch)
tree8f2e35192ccede9621fa6d2c6d97058c1eb8404c /activesupport/lib/active_support
parentcb5b0cf93ff45c3f08ac6b6ce524846419275067 (diff)
parent7b53d1372df4bbc7a539b5e493ff1491ec460397 (diff)
downloadrails-3cc6995e714bc763b40eb3e1d710c1e5ded44384.tar.gz
rails-3cc6995e714bc763b40eb3e1d710c1e5ded44384.tar.bz2
rails-3cc6995e714bc763b40eb3e1d710c1e5ded44384.zip
Merge pull request #2532 from hasclass/as_json__encode_infinite_and_nan_floats_as_null
JSON: Encode infinite or NaN floats as `null` to generate valid JSON.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/json/encoding.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index b2adfea273..e0dee0e072 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -182,6 +182,10 @@ class Numeric
def encode_json(encoder) to_s end #:nodoc:
end
+class Float
+ def as_json(options = nil) finite? ? self : NilClass::AS_JSON end #:nodoc:
+end
+
class BigDecimal
# A BigDecimal would be naturally represented as a JSON number. Most libraries,
# however, parse non-integer JSON numbers directly as floats. Clients using