chore(ip-restriction): remove redundant length check (#4865)

They are guaranteed by the schema check.
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
This commit is contained in:
罗泽轩 2021-08-24 09:37:23 +08:00 committed by GitHub
parent fc377a92f8
commit 7b527443ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,7 +67,7 @@ function _M.check_schema(conf)
end
-- we still need this as it is too complex to filter out all invalid IPv6 via regex
if conf.whitelist and #conf.whitelist > 0 then
if conf.whitelist then
for _, cidr in ipairs(conf.whitelist) do
if not core.ip.validate_cidr_or_ip(cidr) then
return false, "invalid ip address: " .. cidr
@ -75,7 +75,7 @@ function _M.check_schema(conf)
end
end
if conf.blacklist and #conf.blacklist > 0 then
if conf.blacklist then
for _, cidr in ipairs(conf.blacklist) do
if not core.ip.validate_cidr_or_ip(cidr) then
return false, "invalid ip address: " .. cidr
@ -91,7 +91,7 @@ function _M.restrict(conf, ctx)
local block = false
local remote_addr = ctx.var.remote_addr
if conf.blacklist and #conf.blacklist > 0 then
if conf.blacklist then
local matcher = lrucache(conf.blacklist, nil,
core.ip.create_ip_matcher, conf.blacklist)
if matcher then
@ -99,7 +99,7 @@ function _M.restrict(conf, ctx)
end
end
if conf.whitelist and #conf.whitelist > 0 then
if conf.whitelist then
local matcher = lrucache(conf.whitelist, nil,
core.ip.create_ip_matcher, conf.whitelist)
if matcher then