Skip to content

Commit

Permalink
Replaced new-line-in-string check with control-char check; tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rxi committed Aug 19, 2015
1 parent 7f823ab commit 6fdbd28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,10 @@ local function parse_string(str, i, chr)
for j = i + 1, #str do
local x = str:sub(j, j)

if x == "\n" then
decode_error(str, j, "unexpected new line in string")
end
if x:byte() < 32 then
decode_error(str, j, "control character in string")

if last == "\\" then
elseif last == "\\" then
if x == "u" then
local hex = str:sub(j + 1, j + 5)
if not hex:find("%x%x%x%x") then
Expand Down
6 changes: 4 additions & 2 deletions test/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ test("decode invalid", function()
end)


test("decode invalid escape", function()
test("decode invalid string", function()
local t = {
[["\z"]],
[["\1"]],
[["\u000z"]],
[["\ud83d\ude0q"]]
[["\ud83d\ude0q"]],
'"x\ny"',
'"x\0y"',
}
for i, v in ipairs(t) do
local status, err = pcall(json.decode, v)
Expand Down

0 comments on commit 6fdbd28

Please sign in to comment.