diff options
author | Prathamesh Sonpatki <csonpatki@gmail.com> | 2016-10-30 14:12:43 +0530 |
---|---|---|
committer | Prathamesh Sonpatki <csonpatki@gmail.com> | 2016-10-30 20:08:55 +0530 |
commit | 8776f15b448ed88b1108e70f2de22f0b599818aa (patch) | |
tree | a7230885e28610624da1efffed79cbe94bc55daf /activesupport/lib/active_support/json | |
parent | fe1f4b2ad56f010a4e9b93d547d63a15953d9dc2 (diff) | |
download | rails-8776f15b448ed88b1108e70f2de22f0b599818aa.tar.gz rails-8776f15b448ed88b1108e70f2de22f0b599818aa.tar.bz2 rails-8776f15b448ed88b1108e70f2de22f0b599818aa.zip |
Fix an issue with JSON encoding of "Infinity" and "NaN" values
- When `as_json` returns `Infinity` or `NaN` as the value of any of the key,
we don't used to call `as_json` on it as it was treated as primitive.
- This used to pass `Infinity` or `NaN` to `JSON.generate` and Ruby used
to throw an error for `Infinity/NaN not allowed in JSON.`
- This patch changes the code to call `as_json` on these primitives so
that they are converted to proper values before being passed to
`JSON.generate`.
- Fixes #26877.
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r-- | activesupport/lib/active_support/json/encoding.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index cee731417f..6eb73723ad 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -84,7 +84,7 @@ module ActiveSupport when String EscapedString.new(value) when Numeric, NilClass, TrueClass, FalseClass - value + value.as_json when Hash Hash[value.map { |k, v| [jsonify(k), jsonify(v)] }] when Array |