Skip to content

Commit

Permalink
Fix utils.is_valid_cidr
Browse files Browse the repository at this point in the history
  • Loading branch information
vcapparelli committed Mar 27, 2024
1 parent 20c158c commit 08217cb
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,22 +724,11 @@ def is_valid_cidr(string_network):
:rtype: bool
"""
if string_network.count("/") == 1:
try:
mask = int(string_network.split("/")[1])
except ValueError:
return False

if mask < 1 or mask > 32:
return False

try:
socket.inet_aton(string_network.split("/")[0])
except OSError:
return False
else:
try:
interface = ipaddress.ip_interface(string_network)
except (ipaddress.AddressValueError, ValueError):
return False
return True
return string_network in (interface.compressed, interface.exploded)


@contextlib.contextmanager
Expand Down

0 comments on commit 08217cb

Please sign in to comment.