diff --git a/src/serpent.lua b/src/serpent.lua index 01a2e8b..fe0b442 100644 --- a/src/serpent.lua +++ b/src/serpent.lua @@ -1,4 +1,4 @@ -local n, v = "serpent", 0.231 -- (C) 2012-13 Paul Kulchenko; MIT License +local n, v = "serpent", 0.24 -- (C) 2012-13 Paul Kulchenko; MIT License local c, d = "Paul Kulchenko", "Lua serializer and pretty printer" local snum = {[tostring(1/0)]='1/0 --[[math.huge]]',[tostring(-1/0)]='-1/0 --[[-math.huge]]',[tostring(0/0)]='0/0'} local badtype = {thread = true, userdata = true, cdata = true} @@ -56,7 +56,7 @@ local function s(t, opts) if next(t) == nil then return tag..'{}'..comment(t, level) end -- table empty local maxn, o, out = #t, {}, {} for key = 1, maxn do table.insert(o, key) end - for key in pairs(t) do if not o[key] then table.insert(o, key) end end + for key in pairs(t) do if not o[key] or key > maxn then table.insert(o, key) end end if opts.sortkeys then alphanumsort(o, t, opts.sortkeys) end for n, key in ipairs(o) do local value, ktype, plainindex = t[key], type(key), n <= maxn and not sparse diff --git a/t/test.lua b/t/test.lua index 840efba..2e4644f 100644 --- a/t/test.lua +++ b/t/test.lua @@ -213,4 +213,15 @@ do assert(_a.ud.ud == _a.ud.ud.ud, "userdata with __serialize that returns userdata 4: failed") end +-- test that numerical keys are all present in the serialized table +do + local a = {[4]=1,[5]=1,[6]=1,[7]=1,[8]=1,[9]=1,[10]=1} + local f = assert(loadstring(serpent.dump(a)), + "serializing table with numerical keys: failed") + local _a = f() + for k,v in pairs(a) do + assert(_a[k] == v, "numerical keys are all present: failed") + end +end + print("All tests passed.")