summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc/cbi.lua
diff options
context:
space:
mode:
Diffstat (limited to 'libs/web/luasrc/cbi.lua')
-rw-r--r--libs/web/luasrc/cbi.lua33
1 files changed, 24 insertions, 9 deletions
diff --git a/libs/web/luasrc/cbi.lua b/libs/web/luasrc/cbi.lua
index 403935aec..6c9e7a544 100644
--- a/libs/web/luasrc/cbi.lua
+++ b/libs/web/luasrc/cbi.lua
@@ -1358,20 +1358,35 @@ end
-- Validate the form value
function AbstractValue.validate(self, value)
- if self.datatype and value and datatypes[self.datatype] then
- if type(value) == "table" then
- local v
- for _, v in ipairs(value) do
- if v and #v > 0 and not datatypes[self.datatype](v) then
- return nil
- end
+ if self.datatype and value then
+ local args = { }
+ local dt, ar = self.datatype:match("^(%w+)%(([^%(%)]+)%)")
+
+ if dt and ar then
+ local a
+ for a in ar:gmatch("[^%s,]+") do
+ args[#args+1] = a
end
else
- if not datatypes[self.datatype](value) then
- return nil
+ dt = self.datatype
+ end
+
+ if dt and datatypes[dt] then
+ if type(value) == "table" then
+ local v
+ for _, v in ipairs(value) do
+ if v and #v > 0 and not datatypes[dt](v, unpack(args)) then
+ return nil
+ end
+ end
+ else
+ if not datatypes[dt](value, unpack(args)) then
+ return nil
+ end
end
end
end
+
return value
end