From eb3327cd7558148c39ec240e86ade7ebd0d955d1 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 1 Oct 2013 10:13:17 +0200 Subject: [PATCH] correction in allow_without_dot + test --- test/test_config_domain.py | 6 +++++- tiramisu/option.py | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/test/test_config_domain.py b/test/test_config_domain.py index 018e4c0..f4579a6 100644 --- a/test/test_config_domain.py +++ b/test/test_config_domain.py @@ -8,7 +8,8 @@ from tiramisu.option import DomainnameOption, EmailOption, URLOption, OptionDesc def test_domainname(): d = DomainnameOption('d', '') e = DomainnameOption('e', '', "toto.com") - od = OptionDescription('a', '', [d, e]) + f = DomainnameOption('f', '', allow_without_dot=True) + od = OptionDescription('a', '', [d, f]) c = Config(od) c.read_write() c.d = 'toto.com' @@ -20,6 +21,9 @@ def test_domainname(): raises(ValueError, "c.d = 'toto_super.com'") c.d = 'toto-.com' raises(ValueError, "c.d = 'toto..com'") + # + c.f = 'toto.com' + c.f = 'toto' def test_domainname_netbios(): diff --git a/tiramisu/option.py b/tiramisu/option.py index b894a74..0d0c69a 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -991,16 +991,20 @@ class DomainnameOption(Option): self._allow_without_dot = allow_without_dot end = '' extrachar = '' + extrachar_mandatory = '' if self._type == 'netbios': length = 14 elif self._type == 'hostname': length = 62 elif self._type == 'domainname': length = 62 - extrachar = '\.' + if allow_without_dot is False: + extrachar_mandatory = '\.' + else: + extrachar = '\.' end = '+[a-z]*' - self._domain_re = re.compile(r'^(?:[a-z][a-z\d\-]{{,{0}}}{1}){2}$' - ''.format(length, extrachar, end)) + self._domain_re = re.compile(r'^(?:[a-z][a-z\d\-{0}]{{,{1}}}{2}){3}$' + ''.format(extrachar, length, extrachar_mandatory, end)) super(DomainnameOption, self).__init__(name, doc, default=default, default_multi=default_multi, callback=callback,