mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 05:05:00 -07:00
fix(vim.json): properly treat luanil options as booleans (#28622)
Note: Upstream doesn't have this. It's an Nvim addition.
This commit is contained in:
parent
40ce857797
commit
e15991c811
12
src/cjson/lua_cjson.c
vendored
12
src/cjson/lua_cjson.c
vendored
@ -174,9 +174,9 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* convert null in json objects to lua nil instead of vim.NIL */
|
/* convert null in json objects to lua nil instead of vim.NIL */
|
||||||
int luanil_object;
|
bool luanil_object;
|
||||||
/* convert null in json arrays to lua nil instead of vim.NIL */
|
/* convert null in json arrays to lua nil instead of vim.NIL */
|
||||||
int luanil_array;
|
bool luanil_array;
|
||||||
} json_options_t;
|
} json_options_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -1453,15 +1453,11 @@ static int json_decode(lua_State *l)
|
|||||||
luaL_checktype(l, -1, LUA_TTABLE);
|
luaL_checktype(l, -1, LUA_TTABLE);
|
||||||
|
|
||||||
lua_getfield(l, -1, "object");
|
lua_getfield(l, -1, "object");
|
||||||
if (!lua_isnil(l, -1)) {
|
options.luanil_object = lua_toboolean(l, -1);
|
||||||
options.luanil_object = true;
|
|
||||||
}
|
|
||||||
lua_pop(l, 1);
|
lua_pop(l, 1);
|
||||||
|
|
||||||
lua_getfield(l, -1, "array");
|
lua_getfield(l, -1, "array");
|
||||||
if (!lua_isnil(l, -1)) {
|
options.luanil_array = lua_toboolean(l, -1);
|
||||||
options.luanil_array = true;
|
|
||||||
}
|
|
||||||
/* Also pop the luanil table */
|
/* Also pop the luanil table */
|
||||||
lua_pop(l, 2);
|
lua_pop(l, 2);
|
||||||
break;
|
break;
|
||||||
|
@ -32,6 +32,18 @@ describe('vim.json.decode()', function()
|
|||||||
baz = vim.NIL,
|
baz = vim.NIL,
|
||||||
foo = { a = 'b' },
|
foo = { a = 'b' },
|
||||||
}, exec_lua([[return vim.json.decode(..., {})]], jsonstr))
|
}, exec_lua([[return vim.json.decode(..., {})]], jsonstr))
|
||||||
|
eq(
|
||||||
|
{
|
||||||
|
arr = { 1, 2, vim.NIL },
|
||||||
|
bar = { 3, 7 },
|
||||||
|
baz = vim.NIL,
|
||||||
|
foo = { a = 'b' },
|
||||||
|
},
|
||||||
|
exec_lua(
|
||||||
|
[[return vim.json.decode(..., { luanil = { array = false, object = false } })]],
|
||||||
|
jsonstr
|
||||||
|
)
|
||||||
|
)
|
||||||
eq({
|
eq({
|
||||||
arr = { 1, 2, vim.NIL },
|
arr = { 1, 2, vim.NIL },
|
||||||
bar = { 3, 7 },
|
bar = { 3, 7 },
|
||||||
|
Loading…
Reference in New Issue
Block a user