mirror of
https://github.com/TangentFoxy/rxi-json.lua.git
synced 2025-07-27 18:42:17 +00:00
Added checking and tests for trailing garbage when decoding
This commit is contained in:
7
json.lua
7
json.lua
@@ -388,7 +388,12 @@ function json.decode(str)
|
||||
if type(str) ~= "string" then
|
||||
error("expected argument of type string, got " .. type(str))
|
||||
end
|
||||
return ( parse(str, next_char(str, 1, space_chars, true)) )
|
||||
local res, idx = parse(str, next_char(str, 1, space_chars, true))
|
||||
idx = next_char(str, idx, space_chars, true)
|
||||
if idx <= #str then
|
||||
decode_error(str, idx, "trailing garbage")
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user