Skip to content

Commit b5b93da

Browse files
committed
Fix bug where a scientific notation value was incorrectly parsed if there was no decimal point.
1 parent 92f624f commit b5b93da

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

include/entity/json.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ namespace ent
460460

461461
try
462462
{
463-
if (item.find('.') == string::npos)
463+
// if (item.find('.') == string::npos)
464+
if (item.find_first_of(".eE") == string::npos)
464465
{
465466
return std::stoll(item, nullptr, 0);
466467
}

src/test/json.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,18 @@ TEST_SUITE("json")
163163
"upper": 3.141E-10,
164164
"long": 12345123456789,
165165
"big": 123456789123456789123456789.0,
166-
"tiny": 1.0e-300
166+
"tiny": 1.0e-300,
167+
"pointless": 1e-5
167168
})json");
168169

169-
CHECK(t["integer"].as_long() == 42);
170-
CHECK(t["double"].as_double() == 3.14);
171-
CHECK(t["scientific"].as_double() == 3.141e-10);
172-
CHECK(t["upper"].as_double() == 3.141e-10);
173-
CHECK(t["long"].as_long() == 12345123456789);
174-
CHECK(t["big"].as_double() == 123456789123456789123456789.0);
175-
CHECK(t["tiny"].as_double() == 1.0e-300);
170+
CHECK(t["integer"].as_long() == 42);
171+
CHECK(t["double"].as_double() == 3.14);
172+
CHECK(t["scientific"].as_double() == 3.141e-10);
173+
CHECK(t["upper"].as_double() == 3.141e-10);
174+
CHECK(t["long"].as_long() == 12345123456789);
175+
CHECK(t["big"].as_double() == 123456789123456789123456789.0);
176+
CHECK(t["tiny"].as_double() == 1.0e-300);
177+
CHECK(t["pointless"].as_double() == 1e-5); // Check for scientific notation without a decimal point
176178
}
177179

178180

0 commit comments

Comments
 (0)