mirror of https://github.com/rxi/json.lua.git
Fixed parse_string() to handle "\\" correctly, added tests
parent
50f4512c2c
commit
7f823abd2e
9
json.lua
9
json.lua
|
@ -214,11 +214,12 @@ local function parse_string(str, i, chr)
|
|||
has_unicode_escape = true
|
||||
end
|
||||
else
|
||||
has_escape = true
|
||||
end
|
||||
if not escape_chars[x] then
|
||||
decode_error(str, j, "invalid escape char '" .. x .. "' in string")
|
||||
end
|
||||
has_escape = true
|
||||
end
|
||||
last = nil
|
||||
|
||||
elseif x == '"' then
|
||||
local s = str:sub(i + 1, j - 1)
|
||||
|
@ -232,9 +233,11 @@ local function parse_string(str, i, chr)
|
|||
s = s:gsub("\\.", escape_char_map_inv)
|
||||
end
|
||||
return s, j + 1
|
||||
end
|
||||
|
||||
else
|
||||
last = x
|
||||
end
|
||||
end
|
||||
decode_error(str, i, "expected closing quote for string")
|
||||
end
|
||||
|
||||
|
|
|
@ -152,6 +152,8 @@ test("decode escape", function()
|
|||
[ [["\u263a"]] ] = '☺',
|
||||
[ [["\ud83d\ude02"]] ] = '😂',
|
||||
[ [["\r\n\t\\\""]] ] = '\r\n\t\\"',
|
||||
[ [["\\"]] ] = '\\',
|
||||
[ [["\\\\"]] ] = '\\\\',
|
||||
}
|
||||
for k, v in pairs(t) do
|
||||
local res = json.decode(k)
|
||||
|
|
Loading…
Reference in New Issue