Skip to content

Commit

Permalink
🐛 fix validate_digits function in payment type(#120)
Browse files Browse the repository at this point in the history
* Fix validate_digits actually allowing non digits chars

* linting
  • Loading branch information
romaincaillon authored Jan 7, 2024
1 parent 084ce94 commit 5ebc5bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pydantic_extra_types/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def validate_digits(cls, card_number: str) -> None:
Raises:
PydanticCustomError: If the card number is not all digits.
"""
if not card_number.isdigit():
if not card_number or not all('0' <= c <= '9' for c in card_number):
raise PydanticCustomError('payment_card_number_digits', 'Card number is not all digits')

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions tests/test_types_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def test_validate_digits():
assert PaymentCardNumber.validate_digits(digits) is None
with pytest.raises(PydanticCustomError, match='Card number is not all digits'):
PaymentCardNumber.validate_digits('hello')
with pytest.raises(PydanticCustomError, match='Card number is not all digits'):
PaymentCardNumber.validate_digits('²')


@pytest.mark.parametrize(
Expand Down

0 comments on commit 5ebc5bb

Please sign in to comment.