X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fweb%2Fluasrc%2Fcbi%2Fdatatypes.lua;h=b543d9fe5ee7287ba62397260d5aacd5e1ed4e9b;hp=2fdb5802c409051e9f507b83318448aeefc6e0b3;hb=8ea7eb86151cacf4bb653658267ffdfbadbab09d;hpb=c20dcb3612de13eeb870de31d83e816d93bdc830 diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua index 2fdb5802c..b543d9fe5 100644 --- a/libs/web/luasrc/cbi/datatypes.lua +++ b/libs/web/luasrc/cbi/datatypes.lua @@ -35,7 +35,7 @@ function bool(val) return false end -function uint(val) +function uinteger(val) local n = tonumber(val) if n ~= nil and math.floor(n) == n and n >= 0 then return true @@ -44,7 +44,7 @@ function uint(val) return false end -function int(val) +function integer(val) local n = tonumber(val) if n ~= nil and math.floor(n) == n then return true @@ -53,6 +53,11 @@ function int(val) return false end +function ufloat(val) + local n = tonumber(val) + return ( n ~= nil and n >= 0 ) +end + function float(val) return ( tonumber(val) ~= nil ) end @@ -89,7 +94,7 @@ end function port(val) val = tonumber(val) - return ( val and val >= 1 and val <= 65535 ) + return ( val and val >= 0 and val <= 65535 ) end function portrange(val) @@ -122,10 +127,9 @@ function macaddr(val) end function hostname(val) - if val and val:match("[a-zA-Z0-9_][a-zA-Z0-9_%-%.]*") then - return true -- XXX: ToDo: need better solution + if val and (#val < 254) and val.match(val, "^[a-zA-Z0-9][a-zA-Z0-9%-%.]*[a-zA-Z0-9]$") then + return true end - return false end @@ -149,7 +153,7 @@ function wepkey(val) if (#val == 10) or (#val == 26) then return (val:match("^[a-fA-F0-9]+$") ~= nil) else - return (#v == 5) or (#v == 13) + return (#val == 5) or (#val == 13) end end