diff options
author | Sebi Burkhard <sebi.burkhard@gmail.com> | 2011-08-15 16:54:13 +0700 |
---|---|---|
committer | Sebi Burkhard <sebi.burkhard@gmail.com> | 2011-08-15 16:54:13 +0700 |
commit | 7b53d1372df4bbc7a539b5e493ff1491ec460397 (patch) | |
tree | e0bbc310f37c6c6099cc07973b587ca208ddd89a /activesupport/lib/active_support/json | |
parent | 652ab436db674a112bcbc72d8c73e21f2ced512a (diff) | |
download | rails-7b53d1372df4bbc7a539b5e493ff1491ec460397.tar.gz rails-7b53d1372df4bbc7a539b5e493ff1491ec460397.tar.bz2 rails-7b53d1372df4bbc7a539b5e493ff1491ec460397.zip |
JSON: Encode infinite or NaN floats as null to generate valid JSON.
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r-- | activesupport/lib/active_support/json/encoding.rb | 4 |
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 67698c1cff..a7a09d5bbe 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -186,6 +186,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 |