summaryrefslogtreecommitdiffhomepage
path: root/libs/web
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2012-04-16 16:48:59 +0000
committerJo-Philipp Wich <jow@openwrt.org>2012-04-16 16:48:59 +0000
commitb6c98f9c579e8f18af57962d0e500b5b20bf6439 (patch)
treef9272d564f82b634697746cd1f59d0042d88b5fd /libs/web
parent84dadb80ab8b2af0f761c44d1cdc012ebc6d8a5b (diff)
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
Diffstat (limited to 'libs/web')
-rw-r--r--libs/web/luasrc/http.lua7
1 files changed, 6 insertions, 1 deletions
diff --git a/libs/web/luasrc/http.lua b/libs/web/luasrc/http.lua
index 858540548..60a3e0722 100644
--- a/libs/web/luasrc/http.lua
+++ b/libs/web/luasrc/http.lua
@@ -333,7 +333,12 @@ function write_json(x)
write(" }")
end
elseif type(x) == "number" or type(x) == "boolean" then
- write(tostring(x))
+ if (x ~= x) then
+ -- NaN is the only value that doesn't equal to itself.
+ write("Number.NaN")
+ else
+ write(tostring(x))
+ end
elseif type(x) == "string" then
write("%q" % tostring(x))
end