From 6b0a7f7f8770f5d21730a5f2fa8fcbc695687c43 Mon Sep 17 00:00:00 2001 From: Bruno Thiago <45828157+brunotvs@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:33:03 -0300 Subject: fix: check if table entry is nil or not (#1867) running ```luarocks config local_by_default``` returns ```Error: Unknown entry local_by_default``` and running ```luarocks config local_by_default true``` writes it as a string to the config file: ```lua local_by_default = "true" ``` Same is true to any bool var set as false. This pr aims to fix this issue. --- spec/quick/config.q | 38 ++++++++++++++++++++++++++++++++++++++ src/luarocks/cmd/config.lua | 4 ++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/spec/quick/config.q b/spec/quick/config.q index d6230567..dd2dcd00 100644 --- a/spec/quick/config.q +++ b/spec/quick/config.q @@ -95,3 +95,41 @@ Warning: Failed finding Lua header lua.h (searched at /some/bad/path). You may n LuaRocks may not work correctly when building C modules using this configuration. -------------------------------------------------------------------------------- + + + +================================================================================ +TEST: reports when getting a falsy boolean variable + +RUN: luarocks config local_by_default + +STDOUT: +-------------------------------------------------------------------------------- +false +-------------------------------------------------------------------------------- + + + +================================================================================ +TEST: reports when setting a falsy boolean variable + +RUN: luarocks config local_by_default true + +STDOUT: +-------------------------------------------------------------------------------- +Wrote +local_by_default = true +-------------------------------------------------------------------------------- + + + +================================================================================ +TEST: reports when getting an unknown variable + +RUN: luarocks config foo +EXIT: 1 + +STDERR: +-------------------------------------------------------------------------------- +Error: Unknown entry foo +-------------------------------------------------------------------------------- diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua index e8bda657..c350e42a 100644 --- a/src/luarocks/cmd/config.lua +++ b/src/luarocks/cmd/config.lua @@ -130,7 +130,7 @@ end local function print_entry(var, tbl, is_json) return traverse_varstring(var, tbl, function(t, k) - if not t[k] then + if t[k] == nil then return nil, "Unknown entry " .. k end local val = t[k] @@ -151,7 +151,7 @@ end local function infer_type(var) local typ traverse_varstring(var, cfg, function(t, k) - if t[k] then + if t[k] ~= nil then typ = type(t[k]) end end) -- cgit v1.2.3-55-g6feb