nst/JSONTestSuite

Range and precision for extreme number values

0xced opened this issue · 1 comments

0xced commented

Range and Precision - What about numbers with a huge amount of digits? According to RFC 7159, "A JSON parser MUST accept all texts that conform to the JSON grammar" (section 9). However, according to the same paragraph, "An implementation may set limits on the range and precision of numbers.". So, it is unclear to me whether parsers are allowed to raise errors when they meet extreme values such 1e9999 or 0.0000000000000000000000000000001.

You said it is unclear to me whether parsers are allowed to raise errors but all the extreme values tests are y_* tests. Since the specification is contradictory, I think these tests should be implementation defined instead.

Some parsers, such as jansson and Json.NET has chosen to raise errors:

if((value == HUGE_VAL || value == -HUGE_VAL) && errno == ERANGE) {
    /* Overflow */
    return -1;
}
reader = new JsonTextReader(new StringReader("1E+309"));
ExceptionAssert.Throws<JsonReaderException>(() => reader.Read(), "Input string '1E+309' is not a valid number. Path '', line 1, position 6.");

reader = new JsonTextReader(new StringReader("-1E+5000"));
ExceptionAssert.Throws<JsonReaderException>(() => reader.Read(), "Input string '-1E+5000' is not a valid number. Path '', line 1, position 8.");
0xced commented

I also opened JamesNK/Newtonsoft.Json#1065. 😁