Skip to content

Commit

Permalink
Merge pull request #251 from LeszekSwirski/json-empty-exponent
Browse files Browse the repository at this point in the history
Disallow empty exponent in JSON parsing
  • Loading branch information
lemire authored Jul 22, 2024
2 parents 92c79d0 + b57207c commit 9468d50
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/fast_float/ascii_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ parsed_number_string_t<UC> parse_number_string(UC const *p, UC const * pend, par
++p;
}
if ((p == pend) || !is_integer(*p)) {
if(!(fmt & chars_format::fixed)) {
if(!(fmt & chars_format::fixed) || (fmt & FASTFLOAT_JSONFMT)) {
// We are in error.
return answer;
}
Expand Down
4 changes: 3 additions & 1 deletion tests/json_fmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ int main()
{
const std::vector<double> expected{ -0.2, 0.02, 0.002, 1., 0., std::numeric_limits<double>::infinity() };
const std::vector<std::string> accept{ "-0.2", "0.02", "0.002", "1e+0000", "0e-2", "inf" };
const std::vector<std::string> reject{ "-.2", "00.02", "0.e+1", "00.e+1", ".25", "+0.25", "inf", "nan(snan)" };
const std::vector<std::string> reject{"-.2", "00.02", "0.e+1", "00.e+1",
"1e", "1e+", ".25", "+0.25",
"inf", "nan(snan)"};

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

0 comments on commit 9468d50

Please sign in to comment.