From 78dee18b9d94300e0a9946f23fb94154d7fea8b7 Mon Sep 17 00:00:00 2001 From: Sunny Nguyen Date: Fri, 26 Sep 2025 12:11:35 -0700 Subject: [PATCH 1/2] Fix instance comparison in AbsMax and AbsMin classes - Changed identity comparison (is not) to instance checking (isinstance) - Fixes incorrect behavior when comparing instances of same class --- src/validators/_extremes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/validators/_extremes.py b/src/validators/_extremes.py index fda93f9..3f11ec8 100644 --- a/src/validators/_extremes.py +++ b/src/validators/_extremes.py @@ -23,7 +23,7 @@ class AbsMax: def __ge__(self, other: Any): """GreaterThanOrEqual.""" - return other is not AbsMax + return not isinstance(other, AbsMax) @total_ordering @@ -44,4 +44,4 @@ class AbsMin: def __le__(self, other: Any): """LessThanOrEqual.""" - return other is not AbsMin + return not isinstance(other, AbsMin) From 425cb9d5a1a4e0780a0cfbd4ca37f4d98f5e4746 Mon Sep 17 00:00:00 2001 From: Sunny Nguyen Date: Fri, 26 Sep 2025 12:27:39 -0700 Subject: [PATCH 2/2] Fix IPv4 private IP detection with CIDR notation - Extract IP address part from CIDR notation before checking if private - Fixes validation of addresses like "192.168.1.0/24" with private parameter - Prevents incorrect private/public detection when subnet mask is included --- src/validators/ip_address.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/validators/ip_address.py b/src/validators/ip_address.py index 94a42c6..c7233ee 100644 --- a/src/validators/ip_address.py +++ b/src/validators/ip_address.py @@ -88,7 +88,9 @@ def ipv4( if cidr: if strict and value.count("/") != 1: raise ValueError("IPv4 address was expected in CIDR notation") - return IPv4Network(value, strict=not host_bit) and _check_private_ip(value, private) + # Extract IP part for private check when using CIDR notation + ip_part = value.split('/')[0] if '/' in value else value + return IPv4Network(value, strict=not host_bit) and _check_private_ip(ip_part, private) return IPv4Address(value) and _check_private_ip(value, private) except (ValueError, AddressValueError, NetmaskValueError): return False