validation of an ip if an ip term starts with a zero
This commit is contained in:
parent
384b30210c
commit
029452ccbc
|
@ -21,6 +21,11 @@ def test_ip():
|
||||||
c.b = '0.0.0.0'
|
c.b = '0.0.0.0'
|
||||||
raises(ValueError, "c.b = '255.255.255.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():
|
def test_ip_default():
|
||||||
a = IPOption('a', '', '88.88.88.88')
|
a = IPOption('a', '', '88.88.88.88')
|
||||||
|
|
|
@ -786,6 +786,12 @@ class IPOption(Option):
|
||||||
warnings_only=warnings_only)
|
warnings_only=warnings_only)
|
||||||
|
|
||||||
def _validate(self, value):
|
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:
|
try:
|
||||||
IP('{0}/32'.format(value))
|
IP('{0}/32'.format(value))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
Loading…
Reference in New Issue