libs/web: rework hostname match to not allow arbritary sequences of numbers and dots
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 16 Dec 2011 06:05:51 +0000 (06:05 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 16 Dec 2011 06:05:51 +0000 (06:05 +0000)
libs/web/htdocs/luci-static/resources/cbi.js
libs/web/luasrc/cbi/datatypes.lua

index 8d32b669d18fc2ae36272737e80e96b2715f93e7..e932dac1d0dbc5d10bb90a9b9fe4d93b8b30d1fc 100644 (file)
@@ -153,8 +153,9 @@ var cbi_validators = {
        'hostname': function(v)
        {
                if (v.length <= 253)
-                       return (v.match(/^[a-zA-Z0-9]+$/) != null ||
-                               v.match(/^[a-zA-Z0-9][a-zA-Z0-9\-.]*[a-zA-Z0-9]$/) != null);
+                       return (v.match(/^[a-zA-Z]+$/) != null ||
+                               (v.match(/^[a-zA-Z0-9][a-zA-Z0-9\-.]*[a-zA-Z0-9]$/) &&
+                                v.match(/[^0-9.]/)));
 
                return false;
        },
@@ -191,7 +192,7 @@ var cbi_validators = {
        'neg_network_ip4addr': function(v)
        {
                v = v.replace(/^\s*!/, "");
-               return cbi_validators.uciname(v) || cbi_validators.ip4addr(v);          
+               return cbi_validators.uciname(v) || cbi_validators.ip4addr(v);
        },
 
        'range': function(v, args)
index 9a3b735008a289de333a35a0d88898f76c657eaa..65a8eedeb13d75db545b22c56e292b6c05c77bb8 100644 (file)
@@ -142,8 +142,9 @@ end
 
 function hostname(val)
        if val and (#val < 254) and (
-          val:match("^[a-zA-Z0-9]+$") or
-          val:match("^[a-zA-Z0-9][a-zA-Z0-9%-%.]*[a-zA-Z0-9]$")
+          val:match("^[a-zA-Z]+$") or
+          (val:match("^[a-zA-Z0-9][a-zA-Z0-9%-%.]*[a-zA-Z0-9]$") and
+           val:match("[^0-9%.]"))
        ) then
                return true
        end
@@ -238,7 +239,7 @@ function neg_network_ip4addr(val)
        if type(v) == "string" then
                v = v:gsub("^%s*!", "")
                return (uciname(v) or ip4addr(v))
-       end     
+       end
 end
 
 function range(val, min, max)