libs/web: fix "port" datatype to allow port 0
[project/luci.git] / libs / web / luasrc / cbi / datatypes.lua
index 62f06c4..b543d9f 100644 (file)
@@ -94,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)
@@ -127,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
 
@@ -154,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