pydantic / pydantic-extra-types

Extra Pydantic types.
MIT License
181 stars 48 forks source link

fix validate_digits actually allowing non digit characters #120

Closed romaincaillon closed 8 months ago

romaincaillon commented 8 months ago

str.isdigit method actually allows non digit characters like ² or .

>>> from pydantic_extra_types.payment import PaymentCardNumber
>>> PaymentCardNumber("²")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rcaillon/.local/lib/python3.10/site-packages/pydantic_extra_types/payment.py", line 47, in __init__
    card_number = self.validate_luhn_check_digit(card_number)
  File "/home/rcaillon/.local/lib/python3.10/site-packages/pydantic_extra_types/payment.py", line 108, in validate_luhn_check_digit
    sum_ = int(card_number[-1])
ValueError: invalid literal for int() with base 10: '²'
>>> PaymentCardNumber("⑥")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rcaillon/.local/lib/python3.10/site-packages/pydantic_extra_types/payment.py", line 47, in __init__
    card_number = self.validate_luhn_check_digit(card_number)
  File "/home/rcaillon/.local/lib/python3.10/site-packages/pydantic_extra_types/payment.py", line 108, in validate_luhn_check_digit
    sum_ = int(card_number[-1])
ValueError: invalid literal for int() with base 10: '⑥'
codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (084ce94) 100.00% compared to head (0e8efea) 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #120 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 10 10 Lines 688 688 Branches 176 176 ========================================= Hits 688 688 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.