mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 21:49:06 +02:00
Fix JSON::Coder to call as_json proc for NaN and Infinity
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
This commit is contained in:
parent
dd1fe03b8a
commit
f865148e19
2 changed files with 36 additions and 13 deletions
|
@ -35,4 +35,19 @@ class JSONCoderTest < Test::Unit::TestCase
|
|||
coder = JSON::Coder.new(symbolize_names: true)
|
||||
assert_equal({a: 1}, coder.load('{"a":1}'))
|
||||
end
|
||||
|
||||
def test_json_coder_dump_NaN_or_Infinity
|
||||
coder = JSON::Coder.new(&:inspect)
|
||||
assert_equal "NaN", coder.load(coder.dump(Float::NAN))
|
||||
assert_equal "Infinity", coder.load(coder.dump(Float::INFINITY))
|
||||
assert_equal "-Infinity", coder.load(coder.dump(-Float::INFINITY))
|
||||
end
|
||||
|
||||
def test_json_coder_dump_NaN_or_Infinity_loop
|
||||
coder = JSON::Coder.new(&:itself)
|
||||
error = assert_raise JSON::GeneratorError do
|
||||
coder.dump(Float::NAN)
|
||||
end
|
||||
assert_include error.message, "NaN not allowed in JSON"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue