diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 8dad1d1..6a1c765 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -1227,6 +1227,14 @@ bool OurReader::readToken(Token& token) { ok = features_.allowSpecialFloats_ && match("nfinity", 7); } break; + case '+': + if (readNumber(true)) { + token.type_ = tokenNumber; + } else { + token.type_ = tokenPosInf; + ok = features_.allowSpecialFloats_ && match("nfinity", 7); + } + break; case 't': token.type_ = tokenTrue; ok = match("rue", 3); diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index cc5ebf2..6d3a022 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -2451,17 +2451,19 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) { Json::String errs; Json::CharReader* reader(b.newCharReader()); { - char const doc[] = "{\"a\":NaN,\"b\":Infinity,\"c\":-Infinity}"; + char const doc[] = "{\"a\":NaN,\"b\":Infinity,\"c\":-Infinity,\"d\":+Infinity}"; bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs); JSONTEST_ASSERT(ok); JSONTEST_ASSERT_STRING_EQUAL("", errs); - JSONTEST_ASSERT_EQUAL(3u, root.size()); + JSONTEST_ASSERT_EQUAL(4u, root.size()); double n = root["a"].asDouble(); JSONTEST_ASSERT(std::isnan(n)); JSONTEST_ASSERT_EQUAL(std::numeric_limits::infinity(), root.get("b", 0.0)); JSONTEST_ASSERT_EQUAL(-std::numeric_limits::infinity(), root.get("c", 0.0)); + JSONTEST_ASSERT_EQUAL(std::numeric_limits::infinity(), + root.get("d", 0.0)); } struct TestData { @@ -2485,7 +2487,8 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) { {__LINE__, false, "{\"a\":.Infinity}"}, // {__LINE__, false, "{\"a\":_Infinity}"}, // {__LINE__, false, "{\"a\":_nfinity}"}, // - {__LINE__, true, "{\"a\":-Infinity}"} // + {__LINE__, true, "{\"a\":-Infinity}"}, // + {__LINE__, true, "{\"a\":+Infinity}"} // }; for (const auto& td : test_data) { bool ok = reader->parse(&*td.in.begin(), &*td.in.begin() + td.in.size(), @@ -2499,7 +2502,7 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) { } { - char const doc[] = "{\"posInf\": Infinity, \"NegInf\": -Infinity}"; + char const doc[] = "{\"posInf\": +Infinity, \"NegInf\": -Infinity}"; bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs); JSONTEST_ASSERT(ok); JSONTEST_ASSERT_STRING_EQUAL("", errs);