Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix validate_digits actually allowing non digit characters #120

Merged
merged 2 commits into from
Jan 7, 2024

Conversation

romaincaillon
Copy link
Contributor

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: '⑥'

Copy link

codecov bot commented Jan 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@yezz123 yezz123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks 🙏🏻

@yezz123 yezz123 merged commit 5ebc5bb into pydantic:main Jan 7, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants