Skip to content

fix validate_digits actually allowing non digit characters - #120

Merged
yezz123 merged 2 commits into
pydantic:mainfrom
romaincaillon:fix-digits-validation
Jan 7, 2024
Merged

yezz123 merged 2 commits into
pydantic:mainfrom
romaincaillon:fix-digits-validation

Conversation

@romaincaillon

Copy link
Copy Markdown
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: '⑥'

@codecov

codecov Bot commented Jan 5, 2024 •

Copy link
Copy Markdown

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.

@yezz123 yezz123 left a comment

Copy link
Copy Markdown
Collaborator

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
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