X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fuvl%2Fluasrc%2Fuvl.lua;h=28924a3cc32832a43d655500fe4af1f258bf8f36;hp=9cdb9948dca4f0529bb037a9f35b921096f57de6;hb=9d67f6db0136d94aeff9ebc15fc5e4abee42b03a;hpb=ef8f835894953259e17a2f59b00e7e8173598a06 diff --git a/libs/uvl/luasrc/uvl.lua b/libs/uvl/luasrc/uvl.lua index 9cdb9948d..28924a3cc 100644 --- a/libs/uvl/luasrc/uvl.lua +++ b/libs/uvl/luasrc/uvl.lua @@ -334,12 +334,41 @@ function UVL._validate_option( self, option, nodeps ) return false, option:error(ERR.OPT_DATATYPE(option, dt)) end end - end + + val = ( type(val) == "table" and val or { val } ) + for _, v in ipairs(val) do + if option:scheme('minlength') then + if #v < option:scheme('minlength') then + return false, option:error(ERR.OPT_RANGE(option)) + end + end + + if option:scheme('maxlength') then + if #v > option:scheme('maxlength') then + return false, option:error(ERR.OPT_RANGE(option)) + end + end + + v = tonumber(v) + + if option:scheme('minimum') then + if not v or v < option:scheme('minimum') then + return false, option:error(ERR.OPT_RANGE(option)) + end + end + + if option:scheme('maximum') then + if not v or v > option:scheme('maximum') then + return false, option:error(ERR.OPT_RANGE(option)) + end + end + end - if not nodeps then - local ok, err = dependencies.check( self, option ) - if not ok then - option:error(err) + if not nodeps then + local ok, err = dependencies.check( self, option ) + if not ok then + option:error(err) + end end end @@ -582,6 +611,9 @@ function UVL._parse_var(self, scheme, k, v) t.valueof = type(v2) == "table" and v2 or {v2} elseif k == "required" then t[k] = _bool(v2) + elseif k == "minlength" or k == "maxlength" + or k == "minimum" or k == "maximum" then + t[k] = tonumber(v2) else t[k] = t[k] or v2 end @@ -633,8 +665,10 @@ function UVL._parse_enum(self, scheme, k, v) if not t.values then t.values = { [v.value] = v.title or v.value } + t.valuelist = { {value = v.value, title = v.title} } else t.values[v.value] = v.title or v.value + t.valuelist[#t.valuelist + 1] = {value = v.value, title = v.title} end if not t.enum_depends then @@ -663,20 +697,20 @@ end -- Read a dependency specification function UVL._read_dependency( self, values, deps ) - local expr = "%$?[a-zA-Z0-9_]+" + local expr = "%$?[%w_]+" if values then values = ( type(values) == "table" and values or { values } ) for _, value in ipairs(values) do local condition = { } - for val in value:gmatch("[^%s,]+") do - local k, v = val:match("([^%s=]+)%s*=*%s*([^%s]*)") + for val in value:gmatch("[^,]+") do + local k, e, v = val:match("%s*([%w$_.]+)%s*(=?)%s*(.*)") if k and ( k:match("^"..expr.."%."..expr.."%."..expr.."$") or k:match("^"..expr.."%."..expr.."$") or k:match("^"..expr.."$") ) then - condition[k] = v or true + condition[k] = (e == '=') and v or true else return nil end @@ -848,7 +882,7 @@ function uvlitem.config(self, opt) if #self.cref >= 3 then c = c and c[self.cref[3]] or nil end - end + end if c and opt then return c[opt] @@ -912,7 +946,7 @@ function uvlitem._loadconf(self, co, c) if err then self:error(ERR.UCILOAD(self, err)) end - + self._configcache = co end return co