Skip to content

Commit 80d177a

Browse files
committed
fix(utils): return empty string for nil args_repr
1 parent 4e1211d commit 80d177a

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎spec/utils_spec.lua‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe("mods.utils", function()
6666
-- stylua: ignore
6767
tests = {
6868
---------input----------|------expected--------
69+
{ nil , "" },
6970
{ { } , "" },
7071
{ { "a", 1, true } , '"a", 1, true' },
7172
{ { "x", "y", "z", {} } , '"x", "y", "z", {}' },

‎src/mods/utils.lua‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ function M.keypath(...)
7070
end
7171

7272
function M.args_repr(v)
73-
local s = inspect(v, { process = remove_mt })
74-
return s:gsub("^%s*{%s*(.-)%s*}%s*$", "%1")
73+
if v == nil then
74+
return ""
75+
end
76+
return inspect(v, { process = remove_mt }):gsub("^%s*{%s*(.-)%s*}%s*$", "%1")
7577
end
7678

7779
function M.assert_arg(argn, v, validator, optional, msg)

‎types/utils.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function M.keypath(...) end
5656
---> Requires [`inspect`](https://github.com/kikito/inspect.lua)
5757
---
5858
---@section Formatting
59-
---@param v table|any Value to format.
59+
---@param v any Value to format. `nil` returns an empty string.
6060
---@return string out Argument list string.
6161
---@nodiscard
6262
function M.args_repr(v) end

0 commit comments

Comments
 (0)