libs/web: allow one-character hostnames
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 14 Dec 2011 15:01:54 +0000 (15:01 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 14 Dec 2011 15:01:54 +0000 (15:01 +0000)
libs/web/htdocs/luci-static/resources/cbi.js
libs/web/luasrc/cbi/datatypes.lua

index 5eee59c..123e8e1 100644 (file)
@@ -151,8 +151,10 @@ var cbi_validators = {
        },
 
        'hostname': function(v)
-       {       if ( v.length <= 253 )
-                       return (v.match(/^[a-zA-Z0-9][a-zA-Z0-9\-.]*[a-zA-Z0-9]$/) != null);
+       {
+               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 false;
        },
index fc3048e..3c768ab 100644 (file)
@@ -141,7 +141,10 @@ function macaddr(val)
 end
 
 function hostname(val)
-       if val and (#val < 254) and val.match(val, "^[a-zA-Z0-9][a-zA-Z0-9%-%.]*[a-zA-Z0-9]$") then
+       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]$")
+       ) then
                return true
        end
        return false