mirror of
https://github.com/pkulchenko/serpent.git
synced 2024-11-21 23:24:24 +00:00
Fixed an issue missing numerical keys (fixes #8).
This commit is contained in:
parent
2d09171357
commit
f7b2a819c0
@ -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
|
||||
|
11
t/test.lua
11
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.")
|
||||
|
Loading…
Reference in New Issue
Block a user