aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Thiago <45828157+brunotvs@users.noreply.github.com>2026-03-17 14:33:03 -0300
committerGitHub <noreply@github.com>2026-03-17 14:33:03 -0300
commit6b0a7f7f8770f5d21730a5f2fa8fcbc695687c43 (patch)
tree8fa3c8c6a2d52fc84c2b96762457dab3412e37d7
parentdf425b4a24637797f552245685d7535ad9a56f7c (diff)
downloadluarocks-6b0a7f7f8770f5d21730a5f2fa8fcbc695687c43.tar.gz
luarocks-6b0a7f7f8770f5d21730a5f2fa8fcbc695687c43.tar.bz2
luarocks-6b0a7f7f8770f5d21730a5f2fa8fcbc695687c43.zip
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.
-rw-r--r--spec/quick/config.q38
-rw-r--r--src/luarocks/cmd/config.lua4
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
95 95
96LuaRocks may not work correctly when building C modules using this configuration. 96LuaRocks may not work correctly when building C modules using this configuration.
97-------------------------------------------------------------------------------- 97--------------------------------------------------------------------------------
98
99
100
101================================================================================
102TEST: reports when getting a falsy boolean variable
103
104RUN: luarocks config local_by_default
105
106STDOUT:
107--------------------------------------------------------------------------------
108false
109--------------------------------------------------------------------------------
110
111
112
113================================================================================
114TEST: reports when setting a falsy boolean variable
115
116RUN: luarocks config local_by_default true
117
118STDOUT:
119--------------------------------------------------------------------------------
120Wrote
121local_by_default = true
122--------------------------------------------------------------------------------
123
124
125
126================================================================================
127TEST: reports when getting an unknown variable
128
129RUN: luarocks config foo
130EXIT: 1
131
132STDERR:
133--------------------------------------------------------------------------------
134Error: Unknown entry foo
135--------------------------------------------------------------------------------
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
130 130
131local function print_entry(var, tbl, is_json) 131local function print_entry(var, tbl, is_json)
132 return traverse_varstring(var, tbl, function(t, k) 132 return traverse_varstring(var, tbl, function(t, k)
133 if not t[k] then 133 if t[k] == nil then
134 return nil, "Unknown entry " .. k 134 return nil, "Unknown entry " .. k
135 end 135 end
136 local val = t[k] 136 local val = t[k]
@@ -151,7 +151,7 @@ end
151local function infer_type(var) 151local function infer_type(var)
152 local typ 152 local typ
153 traverse_varstring(var, cfg, function(t, k) 153 traverse_varstring(var, cfg, function(t, k)
154 if t[k] then 154 if t[k] ~= nil then
155 typ = type(t[k]) 155 typ = type(t[k])
156 end 156 end
157 end) 157 end)