Close #12 (serialization bug for string "len")

Thanks to nikki93 for spotting the issue and suggesting this solution.
This commit is contained in:
Robin Wellner 2018-11-04 13:07:19 +00:00 committed by GitHub
parent 4f2680317c
commit e817e4de28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,7 @@ local buf_size = -1
local buf = nil local buf = nil
local writable_buf = nil local writable_buf = nil
local writable_buf_size = nil local writable_buf_size = nil
local SEEN_LEN = {}
local function Buffer_prereserve(min_size) local function Buffer_prereserve(min_size)
if buf_size < min_size then if buf_size < min_size then
@ -222,8 +223,8 @@ serialize_value = function(value, seen)
end end
local t = type(value) local t = type(value)
if t ~= 'number' and t ~= 'boolean' and t ~= 'nil' then if t ~= 'number' and t ~= 'boolean' and t ~= 'nil' then
seen[value] = seen.len seen[value] = seen[SEEN_LEN]
seen.len = seen.len + 1 seen[SEEN_LEN] = seen[SEEN_LEN] + 1
end end
if resource_name_registry[value] then if resource_name_registry[value] then
local name = resource_name_registry[value] local name = resource_name_registry[value]
@ -245,7 +246,7 @@ end
local function serialize(value) local function serialize(value)
Buffer_makeBuffer(4096) Buffer_makeBuffer(4096)
local seen = {len = 0} local seen = {[SEEN_LEN] = 0}
serialize_value(value, seen) serialize_value(value, seen)
end end