better validation for Ip/Network/Netmask Option
This commit is contained in:
parent
ef5bcbf98b
commit
d1c9250e34
@ -192,6 +192,8 @@ class IPOption(Option):
|
|||||||
err = self._impl_valid_unicode(value)
|
err = self._impl_valid_unicode(value)
|
||||||
if err:
|
if err:
|
||||||
return err
|
return err
|
||||||
|
if value.count('.') != 3:
|
||||||
|
return ValueError(_('invalid IP'))
|
||||||
for val in value.split('.'):
|
for val in value.split('.'):
|
||||||
if val.startswith("0") and len(val) > 1:
|
if val.startswith("0") and len(val) > 1:
|
||||||
return ValueError(_('invalid IP')) # pragma: optional cover
|
return ValueError(_('invalid IP')) # pragma: optional cover
|
||||||
@ -330,6 +332,11 @@ class NetworkOption(Option):
|
|||||||
err = self._impl_valid_unicode(value)
|
err = self._impl_valid_unicode(value)
|
||||||
if err:
|
if err:
|
||||||
return 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:
|
try:
|
||||||
IP(value)
|
IP(value)
|
||||||
except ValueError: # pragma: optional cover
|
except ValueError: # pragma: optional cover
|
||||||
@ -354,6 +361,11 @@ class NetmaskOption(Option):
|
|||||||
err = self._impl_valid_unicode(value)
|
err = self._impl_valid_unicode(value)
|
||||||
if err:
|
if err:
|
||||||
return 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:
|
try:
|
||||||
IP('0.0.0.0/{0}'.format(value))
|
IP('0.0.0.0/{0}'.format(value))
|
||||||
except ValueError: # pragma: optional cover
|
except ValueError: # pragma: optional cover
|
||||||
|
Loading…
Reference in New Issue
Block a user