libs/web: fix luci.http.write_json() to properly encode control chars in strings
This commit is contained in:
parent
c9556c02bb
commit
2675ad1c63
1 changed files with 4 additions and 5 deletions
|
@ -4,9 +4,6 @@ LuCI - HTTP-Interaction
|
||||||
Description:
|
Description:
|
||||||
HTTP-Header manipulator and form variable preprocessor
|
HTTP-Header manipulator and form variable preprocessor
|
||||||
|
|
||||||
FileId:
|
|
||||||
$Id$
|
|
||||||
|
|
||||||
License:
|
License:
|
||||||
Copyright 2008 Steven Barth <steven@midlink.org>
|
Copyright 2008 Steven Barth <steven@midlink.org>
|
||||||
|
|
||||||
|
@ -334,12 +331,14 @@ function write_json(x)
|
||||||
end
|
end
|
||||||
elseif type(x) == "number" or type(x) == "boolean" then
|
elseif type(x) == "number" or type(x) == "boolean" then
|
||||||
if (x ~= x) then
|
if (x ~= x) then
|
||||||
-- NaN is the only value that doesn't equal to itself.
|
-- NaN is the only value that doesn't equal to itself.
|
||||||
write("Number.NaN")
|
write("Number.NaN")
|
||||||
else
|
else
|
||||||
write(tostring(x))
|
write(tostring(x))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
write("%q" % tostring(x))
|
write('"%s"' % tostring(x):gsub('["%z\1-\31]', function(c)
|
||||||
|
return '\\u%04x' % c:byte(1)
|
||||||
|
end))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue