Fix JSON NaN

Hi,

The attached patch fixes the JSON generation when dealing with NaN (not
a number), this makes the JSON parsing in the web browser succeed
(before it would get a "nan" which is not a valid JS value)

Chris
This commit is contained in:
Jo-Philipp Wich 2012-04-16 16:48:59 +00:00
parent 84dadb80ab
commit b6c98f9c57

View file

@ -333,7 +333,12 @@ function write_json(x)
write(" }") write(" }")
end end
elseif type(x) == "number" or type(x) == "boolean" then elseif type(x) == "number" or type(x) == "boolean" then
if (x ~= x) then
-- NaN is the only value that doesn't equal to itself.
write("Number.NaN")
else
write(tostring(x)) write(tostring(x))
end
elseif type(x) == "string" then elseif type(x) == "string" then
write("%q" % tostring(x)) write("%q" % tostring(x))
end end