better validation for Ip/Network/Netmask Option
This commit is contained in:
parent
ef5bcbf98b
commit
d1c9250e34
1 changed files with 12 additions and 0 deletions
|
@ -192,6 +192,8 @@ class IPOption(Option):
|
|||
err = self._impl_valid_unicode(value)
|
||||
if err:
|
||||
return err
|
||||
if value.count('.') != 3:
|
||||
return ValueError(_('invalid IP'))
|
||||
for val in value.split('.'):
|
||||
if val.startswith("0") and len(val) > 1:
|
||||
return ValueError(_('invalid IP')) # pragma: optional cover
|
||||
|
@ -330,6 +332,11 @@ class NetworkOption(Option):
|
|||
err = self._impl_valid_unicode(value)
|
||||
if err:
|
||||
return err
|
||||
if value.count('.') != 3:
|
||||
return ValueError(_('invalid network address'))
|
||||
for val in value.split('.'):
|
||||
if val.startswith("0") and len(val) > 1:
|
||||
return ValueError(_('invalid network address'))
|
||||
try:
|
||||
IP(value)
|
||||
except ValueError: # pragma: optional cover
|
||||
|
@ -354,6 +361,11 @@ class NetmaskOption(Option):
|
|||
err = self._impl_valid_unicode(value)
|
||||
if err:
|
||||
return err
|
||||
if value.count('.') != 3:
|
||||
return ValueError(_('invalid netmask address'))
|
||||
for val in value.split('.'):
|
||||
if val.startswith("0") and len(val) > 1:
|
||||
return ValueError(_('invalid netmask address'))
|
||||
try:
|
||||
IP('0.0.0.0/{0}'.format(value))
|
||||
except ValueError: # pragma: optional cover
|
||||
|
|
Loading…
Reference in a new issue