Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range and precision for extreme number values #51

Closed
0xced opened this issue Oct 31, 2016 · 1 comment
Closed

Range and precision for extreme number values #51

0xced opened this issue Oct 31, 2016 · 1 comment

Comments

@0xced
Copy link
Contributor

0xced commented Oct 31, 2016

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
Copy link
Contributor Author

0xced commented Oct 31, 2016

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

@nst nst closed this as completed in a814cbf Nov 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@0xced and others