Skip to content

Commit 402b351

Browse files
committed
fix: reject MAC addresses with mixed separators
Add validation to prevent MAC addresses that use both ':' and '-' separators simultaneously, ensuring consistent separator usage as per MAC address format standards.
1 parent 5440442 commit 402b351

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/validators/mac_address.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ def mac_address(value: str, /):
2929
(Literal[True]): If `value` is a valid MAC address.
3030
(ValidationError): If `value` is an invalid MAC address.
3131
"""
32+
# Check for mixed separators: MAC addresses cannot use both ':' and '-' simultaneously
33+
if ":" in value and "-" in value:
34+
return False
35+
3236
return re.match(r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$", value) if value else False

0 commit comments

Comments
 (0)