Ensure JSON::stringify outputs valid JSON when using inf and nan

This commit is contained in:
FireCatMagic 2024-10-16 21:53:21 -04:00
parent 92e51fca72
commit 21a9fd4c8b

View file

@ -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.