From 043dfadbcebc752d5ab2e9ff08c7e48044d20dc2 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 14 Jan 2025 23:08:50 +0100 Subject: [4.2.x] Fixed #36098 -- Fixed validate_ipv6_address()/validate_ipv46_address() crash for non-string values. Regression in ca2be7724e1244a4cb723de40a070f873c6e94bf. Backport of b3c5830769d8a5dbf2f974da7116fe503c9454d9 from main. --- django/utils/ipv6.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'django') diff --git a/django/utils/ipv6.py b/django/utils/ipv6.py index de41a97f72..487fa7b1e1 100644 --- a/django/utils/ipv6.py +++ b/django/utils/ipv6.py @@ -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 -- cgit v1.3