From 6fdbd28ed9ea1bc50173a6ed7bd77149cf838a6c Mon Sep 17 00:00:00 2001 From: rxi Date: Wed, 19 Aug 2015 19:59:44 +0100 Subject: [PATCH] Replaced new-line-in-string check with control-char check; tests --- json.lua | 7 +++---- test/test.lua | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/json.lua b/json.lua index 5d6536d..b30e7b6 100644 --- a/json.lua +++ b/json.lua @@ -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 diff --git a/test/test.lua b/test/test.lua index 50c354a..784a987 100644 --- a/test/test.lua +++ b/test/test.lua @@ -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)