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:
parent
84dadb80ab
commit
b6c98f9c57
1 changed files with 6 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue