Skip to content

Commit 2cb9a58

Browse files
dota17baylesj
authored andcommitted
reinforce readToken function and add simple tests (#1012)
1 parent c5cb313 commit 2cb9a58

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/lib_json/json_reader.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,14 @@ bool OurReader::readToken(Token& token) {
12271227
ok = features_.allowSpecialFloats_ && match("nfinity", 7);
12281228
}
12291229
break;
1230+
case '+':
1231+
if (readNumber(true)) {
1232+
token.type_ = tokenNumber;
1233+
} else {
1234+
token.type_ = tokenPosInf;
1235+
ok = features_.allowSpecialFloats_ && match("nfinity", 7);
1236+
}
1237+
break;
12301238
case 't':
12311239
token.type_ = tokenTrue;
12321240
ok = match("rue", 3);

src/test_lib_json/main.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,17 +2451,19 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) {
24512451
Json::String errs;
24522452
Json::CharReader* reader(b.newCharReader());
24532453
{
2454-
char const doc[] = "{\"a\":NaN,\"b\":Infinity,\"c\":-Infinity}";
2454+
char const doc[] = "{\"a\":NaN,\"b\":Infinity,\"c\":-Infinity,\"d\":+Infinity}";
24552455
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
24562456
JSONTEST_ASSERT(ok);
24572457
JSONTEST_ASSERT_STRING_EQUAL("", errs);
2458-
JSONTEST_ASSERT_EQUAL(3u, root.size());
2458+
JSONTEST_ASSERT_EQUAL(4u, root.size());
24592459
double n = root["a"].asDouble();
24602460
JSONTEST_ASSERT(std::isnan(n));
24612461
JSONTEST_ASSERT_EQUAL(std::numeric_limits<double>::infinity(),
24622462
root.get("b", 0.0));
24632463
JSONTEST_ASSERT_EQUAL(-std::numeric_limits<double>::infinity(),
24642464
root.get("c", 0.0));
2465+
JSONTEST_ASSERT_EQUAL(std::numeric_limits<double>::infinity(),
2466+
root.get("d", 0.0));
24652467
}
24662468

24672469
struct TestData {
@@ -2485,7 +2487,8 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) {
24852487
{__LINE__, false, "{\"a\":.Infinity}"}, //
24862488
{__LINE__, false, "{\"a\":_Infinity}"}, //
24872489
{__LINE__, false, "{\"a\":_nfinity}"}, //
2488-
{__LINE__, true, "{\"a\":-Infinity}"} //
2490+
{__LINE__, true, "{\"a\":-Infinity}"}, //
2491+
{__LINE__, true, "{\"a\":+Infinity}"} //
24892492
};
24902493
for (const auto& td : test_data) {
24912494
bool ok = reader->parse(&*td.in.begin(), &*td.in.begin() + td.in.size(),
@@ -2499,7 +2502,7 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) {
24992502
}
25002503

25012504
{
2502-
char const doc[] = "{\"posInf\": Infinity, \"NegInf\": -Infinity}";
2505+
char const doc[] = "{\"posInf\": +Infinity, \"NegInf\": -Infinity}";
25032506
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
25042507
JSONTEST_ASSERT(ok);
25052508
JSONTEST_ASSERT_STRING_EQUAL("", errs);

0 commit comments

Comments
 (0)