1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[5.0.x] Fixed #36098 -- Fixed validate_ipv6_address()/validate_ipv46_address() crash for non-string values.

Regression in ca2be7724e.

Backport of b3c5830769 from main.
This commit is contained in:
Mariusz Felisiak
2025-01-14 23:08:50 +01:00
committed by Natalia
parent 61fed511f1
commit 21dfd30d69
6 changed files with 65 additions and 4 deletions

View File

@@ -49,12 +49,14 @@ def clean_ipv6_address(
return str(addr)
def is_valid_ipv6_address(ip_str):
def is_valid_ipv6_address(ip_addr):
"""
Return whether or not the `ip_str` string is a valid IPv6 address.
Return whether the `ip_addr` object is a valid IPv6 address.
"""
if isinstance(ip_addr, ipaddress.IPv6Address):
return True
try:
_ipv6_address_from_str(ip_str)
except ValueError:
_ipv6_address_from_str(ip_addr)
except (TypeError, ValueError):
return False
return True