Skip to content

Commit e8e4626

Browse files
authored
Merge pull request #328 from Vhuynh25/master
Ignore NaN and infinite values in json::wvalue
2 parents e958cef + 07a2422 commit e8e4626

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/crow/json.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
#include <boost/algorithm/string/predicate.hpp>
1717
#include <boost/operators.hpp>
1818
#include <vector>
19+
#include <math.h>
1920

2021
#include "crow/settings.h"
2122
#include "crow/returnable.h"
23+
#include "crow/logging.h"
2224

2325
#if defined(__GNUG__) || defined(__clang__)
2426
#define crow_json_likely(x) __builtin_expect(x, 1)
@@ -1772,6 +1774,12 @@ namespace crow
17721774
{
17731775
if (v.nt == num_type::Floating_point)
17741776
{
1777+
if (isnan(v.num.d) || isinf(v.num.d))
1778+
{
1779+
out += "null";
1780+
CROW_LOG_WARNING << "Invalid JSON value detected (" << v.num.d << "), value set to null";
1781+
break;
1782+
}
17751783
#ifdef _MSC_VER
17761784
#define MSC_COMPATIBLE_SPRINTF(BUFFER_PTR, FORMAT_PTR, VALUE) sprintf_s((BUFFER_PTR), 128, (FORMAT_PTR), (VALUE))
17771785
#else

0 commit comments

Comments
 (0)