Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/validators/i18n/fi.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def fi_business_id(value: str, /):
"""
if not value:
return False
if not re.match(_business_id_pattern(), value):
if not re.fullmatch(_business_id_pattern(), value):
return False
factors = [7, 9, 10, 5, 8, 4, 2]
numbers = map(int, value[:7])
Expand Down Expand Up @@ -92,7 +92,7 @@ def fi_ssn(value: str, /, *, allow_temporal_ssn: bool = True):
if not value:
return False
ssn_check_marks = "0123456789ABCDEFHJKLMNPRSTUVWXY"
if not (result := re.match(_ssn_pattern(ssn_check_marks), value)):
if not (result := re.fullmatch(_ssn_pattern(ssn_check_marks), value)):
return False
gd = result.groupdict()
checksum = int(gd["date"] + gd["serial"])
Expand Down
2 changes: 1 addition & 1 deletion src/validators/i18n/fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def fr_ssn(value: str):
"""
if not value:
return False
matched = re.match(_ssn_pattern(), value)
matched = re.fullmatch(_ssn_pattern(), value)
if not matched:
return False
groups = list(matched.groups())
Expand Down
2 changes: 1 addition & 1 deletion src/validators/i18n/ind.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def ind_aadhar(value: str):
(Literal[True]): If `value` is a valid aadhar card number.
(ValidationError): If `value` is an invalid aadhar card number.
"""
return re.match(r"^[2-9]{1}\d{3}\s\d{4}\s\d{4}$", value)
return re.fullmatch(r"^[2-9]{1}\d{3}\s\d{4}\s\d{4}$", value)


@validator
Expand Down
2 changes: 1 addition & 1 deletion src/validators/mac_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def mac_address(value: str, /):
if ":" in value and "-" in value:
return False

return re.match(r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$", value) if value else False
return re.fullmatch(r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$", value) if value else False
31 changes: 31 additions & 0 deletions tests/test_complete_values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Validate complete MAC addresses and regional identifiers."""

from typing import Callable

import pytest

from validators import ValidationError, mac_address
from validators.i18n.fi import fi_business_id, fi_ssn
from validators.i18n.fr import fr_ssn
from validators.i18n.ind import ind_aadhar


@pytest.mark.parametrize(
"validate,value",
[
(mac_address, "01:23:45:67:ab:CD"),
(mac_address, "01-23-45-67-ab-CD"),
(fi_business_id, "0112038-9"),
(fi_ssn, "010101-0101"),
(fr_ssn, "1 84 12 76 451 089 46"),
(fr_ssn, "1 84 12 76 451 089"),
(ind_aadhar, "3675 9834 6015"),
],
)
@pytest.mark.parametrize("suffix", ["", "\n", "\r\n", " ", "\nextra"])
def test_complete_identifier(validate: Callable[[str], object], value: str, suffix: str):
"""Accept the identifier alone and reject any trailing characters."""
if suffix:
assert isinstance(validate(value + suffix), ValidationError)
else:
assert validate(value) is True
Loading