💥 implemented new handling of NaN and INF #70 #329 #388

- If an overflow occurs during parsing a number from a JSON text, an
exception (std::out_of_range for the moment, to be replaced by a
user-defined exception #244) is thrown so that the overflow is detected
early and roundtripping is guaranteed.
- NaN and INF floating-point values can be stored in a JSON value and
are not replaced by null. That is, the basic_json class behaves like
double in this regard (no exception occurs). However, NaN and INF are
serialized to “null”.
- Adjusted test cases appropriately.
This commit is contained in:
Niels Lohmann 2017-03-12 18:38:05 +01:00
parent 9355f05888
commit 8feaf8dc94
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
8 changed files with 100 additions and 46 deletions

View file

@ -460,7 +460,6 @@ TEST_CASE("nst's JSONTestSuite")
"test/data/nst_json_testsuite/test_parsing/y_number_after_space.json",
"test/data/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json",
"test/data/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json",
"test/data/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
"test/data/nst_json_testsuite/test_parsing/y_number_int_with_exp.json",
"test/data/nst_json_testsuite/test_parsing/y_number_minus_zero.json",
"test/data/nst_json_testsuite/test_parsing/y_number_negative_int.json",
@ -472,9 +471,7 @@ TEST_CASE("nst's JSONTestSuite")
"test/data/nst_json_testsuite/test_parsing/y_number_real_exponent.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_underflow.json",
"test/data/nst_json_testsuite/test_parsing/y_number_simple_int.json",
"test/data/nst_json_testsuite/test_parsing/y_number_simple_real.json",
@ -765,9 +762,6 @@ TEST_CASE("nst's JSONTestSuite")
{
for (auto filename :
{
// we currently do not limit exponents
"test/data/nst_json_testsuite/test_parsing/i_number_neg_int_huge_exp.json",
"test/data/nst_json_testsuite/test_parsing/i_number_pos_double_huge_exp.json",
// we do not pose a limit on nesting
"test/data/nst_json_testsuite/test_parsing/i_structure_500_nested_arrays.json",
// we silently ignore BOMs
@ -787,6 +781,26 @@ TEST_CASE("nst's JSONTestSuite")
}
}
// numbers that overflow during parsing
SECTION("i/y -> n (out of range)")
{
for (auto filename :
{
"test/data/nst_json_testsuite/test_parsing/i_number_neg_int_huge_exp.json",
"test/data/nst_json_testsuite/test_parsing/i_number_pos_double_huge_exp.json",
"test/data/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json"
}
)
{
CAPTURE(filename);
std::ifstream f(filename);
json j;
CHECK_THROWS_AS(j << f, std::out_of_range);
}
}
SECTION("i -> n")
{
for (auto filename :