Merge pull request #33 from crowdsecurity/fix_empty_ret_code

Fix empty ret_code behavior and empty line in config
This commit is contained in:
AlteredCoder 2022-03-31 17:09:57 +02:00 committed by GitHub
commit 57bfc35500
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -22,8 +22,8 @@ function M.new(template_path, redirect_location, ret_code)
end
end
if ret_code_ok == false then
ngx.log(ngx.ERR, "RET_CODE '" .. ret_code .. "' is not supported")
if ret_code_ok == false and ret_code ~= 0 and ret_code ~= "" then
ngx.log(ngx.ERR, "RET_CODE '" .. ret_code .. "' is not supported, using default HTTP code " .. M.ret_code)
end
template_file_ok = false

View file

@ -30,6 +30,11 @@ local function starts_with(str, start)
return str:sub(1, #start) == start
end
local function trim(s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
function config.loadConfig(file)
if not config.file_exists(file) then
return nil, "File ".. file .." doesn't exist"
@ -55,6 +60,9 @@ function config.loadConfig(file)
if starts_with(line, "#") then
isOk = true
end
if trim(line) == "" then
isOk = true
end
if not isOk then
local s = split(line, "=")
for k, v in pairs(s) do