summaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-10-25 00:30:04 +0200
committerwm4 <wm4@nowhere>2019-10-25 00:30:04 +0200
commit7ac622bc5fa2c58e529e4865d4e2264f66ac7116 (patch)
tree6c1818e199cc460d818798d3d79d0a680d14472c /misc
parent77f309c94ff17f5627290a7a5a4477db714ecd1e (diff)
downloadmpv-7ac622bc5fa2c58e529e4865d4e2264f66ac7116.tar.bz2
mpv-7ac622bc5fa2c58e529e4865d4e2264f66ac7116.tar.xz
json: write NaN/Infinity float values as strings
JSON doesn't support these for some god-awful reason. (JSON would have been so much better if it weren't based on JavaScript, the plague of this world.) We don't really care whether these specific values "round trip", so we might as well write them in a standard-compliant way. Untested. I was too lazy to even run this, but it probably works. See #6691.
Diffstat (limited to 'misc')
-rw-r--r--misc/json.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/misc/json.c b/misc/json.c
index d1b2afddb6..d25e0f55c8 100644
--- a/misc/json.c
+++ b/misc/json.c
@@ -299,9 +299,11 @@ static int json_append(bstr *b, const struct mpv_node *src, int indent)
case MPV_FORMAT_INT64:
bstr_xappend_asprintf(NULL, b, "%"PRId64, src->u.int64);
return 0;
- case MPV_FORMAT_DOUBLE:
- bstr_xappend_asprintf(NULL, b, "%f", src->u.double_);
+ case MPV_FORMAT_DOUBLE: {
+ const char *px = isfinite(src->u.double_) ? "" : "\"";
+ bstr_xappend_asprintf(NULL, b, "%s%f%s", px, src->u.double_, px);
return 0;
+ }
case MPV_FORMAT_STRING:
write_json_str(b, src->u.string);
return 0;