json: do something remotely reasonable when we see NaN/infinity
authorLennart Poettering <lennart@poettering.net>
Tue, 26 Oct 2021 13:45:49 +0000 (15:45 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 10 Nov 2021 14:01:30 +0000 (15:01 +0100)
commit06444b314b863facdb173f10f2d1ff11196755d2
treeda5de9861fc2c7c8509b4fb85f686d7d93ce84e0
parente1e32516f98a1f39ce763545de9a8664526d0b8a
json: do something remotely reasonable when we see NaN/infinity

JSON doesn't have NaN/infinity/-infinity concepts in the spec.
Implementations vary what they do with it. JSON5 + Python simply
generate special words "NAN" and "Inifinity" from it. Others generate
"null" for it.

At this point we never actually want to output this, so let's be
conservative and generate RFC compliant JSON, i.e. convert to null.

One day should JSON5 actually become a thing we can revisit this, but in
that case we should implement things via a flag, and only optinally
process nan/infinity/-infinity.

This patch is extremely simple: whenever accepting a
nan/infinity/-infinity from outside it converts it to NULL. I.e. we
convert on input, not output.

(cherry picked from commit 8f1daefce6e952f2fad9510e5101b5fc675d363f)
src/shared/json.c