aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2023-12-07 08:01:27 -0800
committerGitHub <noreply@github.com>2023-12-07 08:01:27 -0800
commitb2d471ab337e56f660eb7c89ae24f447f7b7a165 (patch)
treeabe7805ed1c92d21d146c07c41b57b489da19a5b /src
parent4a34da82c18e6da1e46d6bf3d21082a6b6c8b947 (diff)
downloadrneovim-b2d471ab337e56f660eb7c89ae24f447f7b7a165.tar.gz
rneovim-b2d471ab337e56f660eb7c89ae24f447f7b7a165.tar.bz2
rneovim-b2d471ab337e56f660eb7c89ae24f447f7b7a165.zip
fix(lua): allow nil values in serialized Lua arrays (#26329)
When we convert a Lua table to an Object, we consider the table a "dictionary" if it contains only string keys, and an array if it contains all numeric indices with no gaps. While rare, Lua tables can have both strictly numeric indices and gaps (e.g. { [2] = 2 }). These currently cannot be serialized because it is not considered an array. However, we know the maximum index of the table and as long as all of the keys in the table are numeric, it is still possible to serialize this table as an array. The missing indices will have nil values.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/lua/converter.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index fd2bdbd677..ca0be28fac 100644
--- a/src/nvim/lua/converter.c
+++ b/src/nvim/lua/converter.c
@@ -148,7 +148,7 @@ static LuaTableProps nlua_traverse_table(lua_State *const lstate)
}
} else {
if (tsize == 0
- || (tsize == ret.maxidx
+ || (tsize <= ret.maxidx
&& other_keys_num == 0
&& ret.string_keys_num == 0)) {
ret.type = kObjectTypeArray;
@@ -1129,10 +1129,6 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
}
const size_t idx = cur.obj->data.array.size++;
lua_rawgeti(lstate, -1, (int)idx + 1);
- if (lua_isnil(lstate, -1)) {
- lua_pop(lstate, 2);
- continue;
- }
kvi_push(stack, cur);
cur = (ObjPopStackItem) {
.obj = &cur.obj->data.array.items[idx],