Ensure JSON::stringify outputs valid JSON when using inf and nan
This commit is contained in:
parent
92e51fca72
commit
21a9fd4c8b
1 changed files with 6 additions and 0 deletions
|
@ -31,6 +31,7 @@
|
|||
#include "json.h"
|
||||
|
||||
#include "core/config/engine.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/string/print_string.h"
|
||||
|
||||
const char *JSON::tk_name[TK_MAX] = {
|
||||
|
@ -70,6 +71,11 @@ String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_
|
|||
return itos(p_var);
|
||||
case Variant::FLOAT: {
|
||||
double num = p_var;
|
||||
|
||||
if (!Math::is_finite(num)) {
|
||||
return "\"" + String::num(num) + "\"";
|
||||
}
|
||||
|
||||
if (p_full_precision) {
|
||||
// Store unreliable digits (17) instead of just reliable
|
||||
// digits (14) so that the value can be decoded exactly.
|
||||
|
|
Loading…
Reference in a new issue