Merge pull request #251 from LeszekSwirski/json-empty-exponent

Disallow empty exponent in JSON parsing
This commit is contained in:
Daniel Lemire 2024-07-22 09:07:08 -04:00 committed by GitHub
commit 9468d50c89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -349,7 +349,7 @@ parsed_number_string_t<UC> parse_number_string(UC const *p, UC const * pend, par
++p; ++p;
} }
if ((p == pend) || !is_integer(*p)) { if ((p == pend) || !is_integer(*p)) {
if(!(fmt & chars_format::fixed)) { if(!(fmt & chars_format::fixed) || (fmt & FASTFLOAT_JSONFMT)) {
// We are in error. // We are in error.
return answer; return answer;
} }

View File

@ -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<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> 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) for (std::size_t i = 0; i < accept.size(); ++i)
{ {