forked from Dependencies/lua-json
Replaced new-line-in-string check with control-char check; tests
parent
7f823abd2e
commit
6fdbd28ed9
7
json.lua
7
json.lua
|
@ -198,11 +198,10 @@ local function parse_string(str, i, chr)
|
||||||
for j = i + 1, #str do
|
for j = i + 1, #str do
|
||||||
local x = str:sub(j, j)
|
local x = str:sub(j, j)
|
||||||
|
|
||||||
if x == "\n" then
|
if x:byte() < 32 then
|
||||||
decode_error(str, j, "unexpected new line in string")
|
decode_error(str, j, "control character in string")
|
||||||
end
|
|
||||||
|
|
||||||
if last == "\\" then
|
elseif last == "\\" then
|
||||||
if x == "u" then
|
if x == "u" then
|
||||||
local hex = str:sub(j + 1, j + 5)
|
local hex = str:sub(j + 1, j + 5)
|
||||||
if not hex:find("%x%x%x%x") then
|
if not hex:find("%x%x%x%x") then
|
||||||
|
|
|
@ -133,12 +133,14 @@ test("decode invalid", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
test("decode invalid escape", function()
|
test("decode invalid string", function()
|
||||||
local t = {
|
local t = {
|
||||||
[["\z"]],
|
[["\z"]],
|
||||||
[["\1"]],
|
[["\1"]],
|
||||||
[["\u000z"]],
|
[["\u000z"]],
|
||||||
[["\ud83d\ude0q"]]
|
[["\ud83d\ude0q"]],
|
||||||
|
'"x\ny"',
|
||||||
|
'"x\0y"',
|
||||||
}
|
}
|
||||||
for i, v in ipairs(t) do
|
for i, v in ipairs(t) do
|
||||||
local status, err = pcall(json.decode, v)
|
local status, err = pcall(json.decode, v)
|
||||||
|
|
Loading…
Reference in New Issue