Skip to content

Commit b57207c

Browse files
committed
Disallow empty exponent in JSON parsing
The JSON spec requires at least one digit in the exponential part, if specified.
1 parent 92c79d0 commit b57207c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

include/fast_float/ascii_number.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ parsed_number_string_t<UC> parse_number_string(UC const *p, UC const * pend, par
349349
++p;
350350
}
351351
if ((p == pend) || !is_integer(*p)) {
352-
if(!(fmt & chars_format::fixed)) {
352+
if(!(fmt & chars_format::fixed) || (fmt & FASTFLOAT_JSONFMT)) {
353353
// We are in error.
354354
return answer;
355355
}

tests/json_fmt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ int main()
4040
{
4141
const std::vector<double> expected{ -0.2, 0.02, 0.002, 1., 0., std::numeric_limits<double>::infinity() };
4242
const std::vector<std::string> accept{ "-0.2", "0.02", "0.002", "1e+0000", "0e-2", "inf" };
43-
const std::vector<std::string> reject{ "-.2", "00.02", "0.e+1", "00.e+1", ".25", "+0.25", "inf", "nan(snan)" };
43+
const std::vector<std::string> reject{"-.2", "00.02", "0.e+1", "00.e+1",
44+
"1e", "1e+", ".25", "+0.25",
45+
"inf", "nan(snan)"};
4446

4547
for (std::size_t i = 0; i < accept.size(); ++i)
4648
{

0 commit comments

Comments
 (0)