gears.table.join: Ignore nil arguments (#2440)

When calling join with e.g. arguments (nil, {"a"}), then everything past
the nil was ignored, because the code internally used ipairs() to
iterate over the arguments and this stops at the first nil it
encounters.

Fix this by using select() to iterate over the arguments.

This also adds a unit test for this problem.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2018-10-16 16:17:45 +02:00 committed by Emmanuel Lepage Vallée
parent aa16d77d15
commit 4744a744f0
2 changed files with 9 additions and 1 deletions

View File

@ -18,7 +18,8 @@ local gtable = {}
-- @return A new table containing all keys from the arguments.
function gtable.join(...)
local ret = {}
for _, t in ipairs({...}) do
for i = 1, select("#", ...) do
local t = select(i, ...)
if t then
for k, v in pairs(t) do
if type(k) == "number" then

View File

@ -41,4 +41,11 @@ describe("gears.table", function()
assert.is.equal(f(), nil)
end)
end)
describe("table.join", function()
it("nil argument", function()
local t = gtable.join({"a"}, nil, {"b"})
assert.is.same(t, {"a", "b"})
end)
end)
end)