From 029452ccbc69f1d1d36a6bfd90c73ad3b0cef5f9 Mon Sep 17 00:00:00 2001 From: gwen Date: Mon, 2 Dec 2013 15:10:05 +0100 Subject: [PATCH] validation of an ip if an ip term starts with a zero --- test/test_config_ip.py | 5 +++++ tiramisu/option.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/test/test_config_ip.py b/test/test_config_ip.py index b7d3010..581cbd2 100644 --- a/test/test_config_ip.py +++ b/test/test_config_ip.py @@ -21,6 +21,11 @@ def test_ip(): c.b = '0.0.0.0' raises(ValueError, "c.b = '255.255.255.0'") + raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')") + d = IPOption('a', 'ip', default='192.0.23.1') + od = OptionDescription('od', '', [d]) + c = Config(od) + raises(ValueError, "c.a = '192.000.023.01'") def test_ip_default(): a = IPOption('a', '', '88.88.88.88') diff --git a/tiramisu/option.py b/tiramisu/option.py index 88da41a..7cdf0a4 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -786,6 +786,12 @@ class IPOption(Option): warnings_only=warnings_only) def _validate(self, value): + # sometimes an ip term starts with a zero + # but this does not fit in some case, for example bind does not like it + for val in value.split('.'): + if val.startswith("0") and len(val)>1: + raise ValueError(_('invalid IP')) + # 'standard' validation try: IP('{0}/32'.format(value)) except ValueError: