a hostname shall not start with a number
authorgwen <gremond@cadoles.com>
Tue, 25 Feb 2014 14:20:03 +0000 (15:20 +0100)
committergwen <gremond@cadoles.com>
Tue, 25 Feb 2014 14:20:03 +0000 (15:20 +0100)
test/test_config_domain.py
tiramisu/option.py

index fd9f0cc..9fd9ed3 100644 (file)
@@ -25,15 +25,19 @@ def test_domainname():
     c.f = 'toto.com'
     c.f = 'toto'
 
-def test_domainname_special():
-    """domain name option that starts with a number
+def test_special_domain_name():
+    """domain name option that starts with a number or not
     """
     d = DomainnameOption('d', '')
-    od = OptionDescription('a', '', [d])
+    e = DomainnameOption('e', '', type_='netbios')
+    od = OptionDescription('a', '', [d,e])
     c = Config(od)
     c.read_write()
     c.d = '1toto.com'
     c.d = '123toto.com'
+    c.e = 'toto'
+    raises(ValueError, "c.e = '1toto'")
+
 
 def test_domainname_netbios():
     d = DomainnameOption('d', '', type_='netbios')
index 4c16aa9..8b5eb68 100644 (file)
@@ -993,6 +993,10 @@ class DomainnameOption(Option):
         end = ''
         extrachar = ''
         extrachar_mandatory = ''
+        if self._type != 'netbios':
+            allow_number = '\d'
+        else:
+            allow_number = ''
         if self._type == 'netbios':
             length = 14
         elif self._type == 'hostname':
@@ -1004,8 +1008,9 @@ class DomainnameOption(Option):
             else:
                 extrachar = '\.'
             end = '+[a-z]*'
-        self._domain_re = re.compile(r'^(?:[a-z\d][a-z\d\-{0}]{{,{1}}}{2}){3}$'
-                                     ''.format(extrachar, length, extrachar_mandatory, end))
+        self._domain_re = re.compile(r'^(?:[a-z{0}][a-z\d\-{1}]{{,{2}}}{3}){4}$'
+                                     ''.format(allow_number, extrachar, length,
+                                               extrachar_mandatory, end))
         super(DomainnameOption, self).__init__(name, doc, default=default,
                                                default_multi=default_multi,
                                                callback=callback,