Skip to content

There appears to be a bug in json.lua at line 145 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions json/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
-----------------------------------------------------------------------------
local math = require('math')
local string = require("string")
local table = require("table")
local table = require("table")
local load = (_VERSION == "Lua 5.1") and loadstring or load

-----------------------------------------------------------------------------
-- Module declaration
Expand Down Expand Up @@ -141,7 +142,7 @@ function json.decode(s, startPos)
return decode_scanString(s,startPos)
end
if string.sub(s,startPos,startPos+1)=='/*' then
return decode(s, decode_scanComment(s,startPos))
return json.decode(s, decode_scanComment(s,startPos))
end
-- Otherwise, it must be a constant
return decode_scanConstant(s,startPos)
Expand Down Expand Up @@ -233,7 +234,7 @@ function decode_scanNumber(s,startPos)
endPos = endPos + 1
end
local stringValue = 'return ' .. string.sub(s,startPos, endPos-1)
local stringEval = loadstring(stringValue)
local stringEval = load(stringValue)
assert(stringEval, 'Failed to scan number [ ' .. stringValue .. '] in JSON string at position ' .. startPos .. ' : ' .. endPos)
return stringEval(), endPos
end
Expand Down Expand Up @@ -324,17 +325,17 @@ function decode_scanString(s,startPos)
-- a % 2^b == bitwise_and(a, (2^b)-1)
-- 64 = 2^6
-- 4096 = 2^12 (or 2^6 * 2^6)
local x
local z
if n < 0x80 then
x = string.char(n % 0x80)
z = string.char(n % 0x80)
elseif n < 0x800 then
-- [110x xxxx] [10xx xxxx]
x = string.char(0xC0 + (math.floor(n/64) % 0x20), 0x80 + (n % 0x40))
z = string.char(0xC0 + (math.floor(n/64) % 0x20), 0x80 + (n % 0x40))
else
-- [1110 xxxx] [10xx xxxx] [10xx xxxx]
x = string.char(0xE0 + (math.floor(n/4096) % 0x10), 0x80 + (math.floor(n/64) % 0x40), 0x80 + (n % 0x40))
z = string.char(0xE0 + (math.floor(n/4096) % 0x10), 0x80 + (math.floor(n/64) % 0x40), 0x80 + (n % 0x40))
end
table.insert(t, x)
table.insert(t, z)
else
table.insert(t, escapeSequences[string.sub(s, i, j)])
end
Expand Down Expand Up @@ -377,7 +378,7 @@ local escapeList = {
}

function json_private.encodeString(s)
local s = tostring(s)
s = tostring(s)
return s:gsub(".", function(c) return escapeList[c] end) -- SoniEx2: 5.0 compat
end

Expand Down