Fixed new UVL options
[project/luci.git] / libs / uvl / luasrc / uvl.lua
index 683d7a9bb5bf0d96604650319f27d329e13e12f9..28924a3cc32832a43d655500fe4af1f258bf8f36 100644 (file)
@@ -334,6 +334,35 @@ function UVL._validate_option( self, option, nodeps )
                                        return false, option:error(ERR.OPT_DATATYPE(option, dt))
                                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 )
@@ -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