Skip to content

Commit 73e69fe

Browse files
committed
add parameter validation to libjwt.split function
1 parent 0864898 commit 73e69fe

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/resty/libjwt.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ function _M.get_params(params)
2121
return result, ""
2222
end
2323

24+
25+
function _M.split(str, sep)
26+
if str == "" or str == nil then
27+
return nil, "param is required"
28+
end
29+
if type(str) ~= "string" then
30+
return nil, "param should be a string"
31+
end
32+
if type(sep) ~= "string" or sep == "" then
33+
return nil, "separator should be a string"
34+
end
35+
local result = {}
36+
for match in (str .. sep):gmatch("(.-)" .. sep) do
37+
table.insert(result, match)
38+
end
39+
return result, ""
40+
end
41+
2442
function _M.validate(params)
2543
local params, err = _M.get_params(params)
2644
if err ~= "" then

0 commit comments

Comments
 (0)