We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3d1cc91 commit 0879750Copy full SHA for 0879750
1 file changed
Lib/http/cookiejar.py
@@ -537,12 +537,19 @@ def parse_ns_headers(ns_headers):
537
538
def is_ip(text: str):
539
"""Return True if text is a valid IP address."""
540
- from ipaddress import ip_address
541
- text = text.removeprefix('[').removesuffix(']')
+ from ipaddress import IPv4Address, IPv6Address
+ # check for IPv4 address
542
try:
543
- ip_address(text)
+ IPv4Address(text)
544
except ValueError:
545
- return False
+ # check for IPv6 address in []
546
+ if text.startswith('[') and text.endswith(']'):
547
+ try:
548
+ IPv6Address(text.removeprefix('[').removesuffix(']'))
549
+ except ValueError:
550
+ return False
551
+ else:
552
+ return False # not a IPv6 address in []
553
return True
554
def is_HDN(text):
555
"""Return True if text is a host domain name."""
0 commit comments