rapidjson icon indicating copy to clipboard operation
rapidjson copied to clipboard

Add support of parsing INFINITY and NAN according to the standard.

Open ChevronOne opened this issue 1 year ago • 5 comments

Variables of floating point types that have non-normal values, such as INFINITY and NAN, cannot be parsed by GenericDocument::Parse(const Ch* str) even if the flag kParseNanAndInfFlag is set, and that's due to the fact that the parser tests these exceptional values against NaN, Infinity, -Infinity, Inf and -Inf. However, according to the standard, when converting floating point types to string, e.g. using std::to_string(double), these exceptional values get converted as nan, inf or -inf! This pull request fixes this issue (#2099).

ChevronOne avatar Nov 30 '22 17:11 ChevronOne

CLA assistant check
All committers have signed the CLA.

tencent-adm avatar Nov 30 '22 17:11 tencent-adm

Please update the existing unit test as well.

miloyip avatar Nov 30 '22 20:11 miloyip

Oops, I missed that! Done.

ChevronOne avatar Dec 01 '22 03:12 ChevronOne

Hi @miloyip, We would like to adopt these changes next week from our side. However, since I'm not comprehensively familiar with the implementation of this library as a whole, your feedback would be appreciated on whether these changes are adequate to take or otherwise what kind of unwanted side effects they may cause. We're using the library primarily for C++, and as it stands, we have the issue submitted in #2099. Thanks!

ChevronOne avatar Dec 03 '22 06:12 ChevronOne

We faced this issue and see rapidjson crashing for doc.ParseInsitu<kParseNanAndInfFlag | kParseInsituFlag | kParseFullPrecisionFlag>. Can this fix be merged?

benstadin avatar Jun 28 '23 15:06 benstadin