summaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-03-10 13:22:25 +0100
committerJo-Philipp Wich <jo@mein.io>2022-03-10 13:31:11 +0100
commit03bb0e2493840b155d91fb67b4d47385ec363127 (patch)
treed1e7d58c97c204e2544b1139b30de63758e5bc46 /modules
parent315a592d9b153caaa3068ab3850c1a77054d1169 (diff)
luci-compat: fix evaluating `or()` and `and()` datatype expressions
Fixes: #5705 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules')
-rw-r--r--modules/luci-compat/luasrc/cbi/datatypes.lua41
1 files changed, 28 insertions, 13 deletions
diff --git a/modules/luci-compat/luasrc/cbi/datatypes.lua b/modules/luci-compat/luasrc/cbi/datatypes.lua
index c1cf01f9cd..7ef12eaf32 100644
--- a/modules/luci-compat/luasrc/cbi/datatypes.lua
+++ b/modules/luci-compat/luasrc/cbi/datatypes.lua
@@ -13,34 +13,49 @@ module "luci.cbi.datatypes"
_M['or'] = function(v, ...)
- local i
- for i = 1, select('#', ...), 2 do
+ local i, n = 1, select('#', ...)
+ while i <= n do
local f = select(i, ...)
- local a = select(i+1, ...)
if type(f) ~= "function" then
- if f == v then
+ i = i + 1
+ local c = v
+ if type(f) == "number" then
+ c = tonumber(c)
+ end
+ if f == c then
+ return true
+ end
+ else
+ i = i + 2
+ local a = select(i-1, ...)
+ if f(v, unpack(a)) then
return true
end
- i = i - 1
- elseif f(v, unpack(a)) then
- return true
end
end
return false
end
_M['and'] = function(v, ...)
- local i
- for i = 1, select('#', ...), 2 do
+ local i, n = 1, select('#', ...)
+ while i <= n do
local f = select(i, ...)
- local a = select(i+1, ...)
if type(f) ~= "function" then
- if f ~= v then
+ i = i + 1
+ local c = v
+ if type(f) == "number" then
+ c = tonumber(c)
+ end
+ if f ~= c then
return false
end
i = i - 1
- elseif not f(v, unpack(a)) then
- return false
+ else
+ i = i + 2
+ local a = select(i-1, ...)
+ if not f(v, unpack(a)) then
+ return false
+ end
end
end
return true