Skip to content
Open
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
2 changes: 2 additions & 0 deletions stdnum/damm.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def validate(number: str, table: DammTable | None = None) -> str:
"""Check if the number provided passes the Damm algorithm."""
if not bool(number):
raise InvalidFormat()
if not str(number).isascii():
raise InvalidFormat()
try:
valid = checksum(number, table=table) == 0
except Exception: # noqa: B902
Expand Down
2 changes: 1 addition & 1 deletion stdnum/ie/pps.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from stdnum.util import clean


pps_re = re.compile(r'^\d{7}[A-W][ABHWTX]?$')
pps_re = re.compile(r'^[0-9]{7}[A-W][ABHWTX]?$')
"""Regular expression used to check syntax of PPS numbers."""


Expand Down
2 changes: 2 additions & 0 deletions stdnum/iso7064/mod_11_10.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def calc_check_digit(number: str) -> str:

def validate(number: str) -> str:
"""Check whether the check digit is valid."""
if not str(number).isascii():
raise InvalidFormat()
try:
valid = checksum(number) == 1
except Exception: # noqa: B902
Expand Down
2 changes: 2 additions & 0 deletions stdnum/iso7064/mod_11_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def calc_check_digit(number: str) -> str:

def validate(number: str) -> str:
"""Check whether the check digit is valid."""
if not str(number).isascii():
raise InvalidFormat()
try:
valid = checksum(number) == 1
except Exception: # noqa: B902
Expand Down
2 changes: 2 additions & 0 deletions stdnum/iso7064/mod_97_10.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def calc_check_digits(number: str) -> str:

def validate(number: str) -> str:
"""Check whether the check digit is valid."""
if not str(number).isascii():
raise InvalidFormat()
try:
valid = checksum(number) == 1
except Exception: # noqa: B902
Expand Down
2 changes: 2 additions & 0 deletions stdnum/verhoeff.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def validate(number: str) -> str:
"""Check if the number provided passes the Verhoeff checksum."""
if not bool(number):
raise InvalidFormat()
if not str(number).isascii():
raise InvalidFormat()
try:
valid = checksum(number) == 0
except Exception: # noqa: B902
Expand Down
11 changes: 11 additions & 0 deletions tests/test_damm.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,14 @@ http://www.md-software.de/math/DAMM_Quasigruppen.txt
9
>>> damm.checksum('8169', table=table)
0


Non-ASCII digits (here ARABIC-INDIC DIGITs) are not valid and should be
rejected instead of being treated as the digits they look like.

>>> damm.validate('\u0665\u0667\u0662\u0664')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> damm.is_valid('\u0665\u0667\u0662\u0664')
False
11 changes: 11 additions & 0 deletions tests/test_ie_pps.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ The validate() function should check with old format if last letter is W or T.
'1234567TW'
>>> pps.validate('1234567TT')
'1234567TT'


Non-ASCII digits (here ARABIC-INDIC DIGITs) are not valid and should be
rejected instead of being treated as the digits they look like.

>>> pps.validate('\u0661\u0662\u0663\u0664\u0665\u0666\u0667WH')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> pps.is_valid('\u0661\u0662\u0663\u0664\u0665\u0666\u0667WH')
False
11 changes: 11 additions & 0 deletions tests/test_iso11649.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,14 @@ They should all be valid iso11649 structured creditor reference numbers
... '''
>>> [x for x in numbers.splitlines() if x and not stdnum.iso11649.is_valid(x)]
[]


Non-ASCII digits (here ARABIC-INDIC DIGITs) are not valid and should be
rejected instead of being treated as the digits they look like.

>>> stdnum.iso11649.validate('RF\u0661\u0668 \u0665\u0663\u0669\u0660 \u0660\u0667\u0665\u0664 \u0667\u0660\u0663\u0664')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> stdnum.iso11649.is_valid('RF\u0661\u0668 \u0665\u0663\u0669\u0660 \u0660\u0667\u0665\u0664 \u0667\u0660\u0663\u0664')
False
23 changes: 23 additions & 0 deletions tests/test_iso7064.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,26 @@ range of 02 to 98 as is used in IBAN.
'97'
>>> mod_97_10.calc_check_digits('5335')
'98'


Non-ASCII digits (here ARABIC-INDIC DIGITs) are not valid and should be
rejected instead of being treated as the digits they look like.

>>> mod_11_10.validate('\u0667\u0669\u0664\u0666\u0662\u0663')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> mod_11_10.is_valid('\u0667\u0669\u0664\u0666\u0662\u0663')
False
>>> mod_11_2.validate('\u0660\u0667\u0669\u0664\u0660')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> mod_11_2.is_valid('\u0660\u0667\u0669\u0664\u0660')
False
>>> mod_97_10.validate('\u0660\u0668\u0666\u0668\u0666\u0660\u0660\u0661\u0662\u0665\u0666\u0665\u0661\u0665\u0660\u0660\u0661\u0661\u0662\u0661\u0667\u0665\u0661')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> mod_97_10.is_valid('\u0660\u0668\u0666\u0668\u0666\u0660\u0660\u0661\u0662\u0665\u0666\u0665\u0661\u0665\u0660\u0660\u0661\u0661\u0662\u0661\u0667\u0665\u0661')
False
11 changes: 11 additions & 0 deletions tests/test_lei.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,14 @@ These have been found online and should all be valid numbers.
... '''
>>> [x for x in numbers.splitlines() if x and not lei.is_valid(x)]
[]


Non-ASCII digits (here ARABIC-INDIC DIGITs) are not valid and should be
rejected instead of being treated as the digits they look like.

>>> lei.validate('\u0662\u0661\u0663\u0668\u0660\u0660KUD\u0668LAJWSQ\u0669D\u0661\u0665')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> lei.is_valid('\u0662\u0661\u0663\u0668\u0660\u0660KUD\u0668LAJWSQ\u0669D\u0661\u0665')
False
11 changes: 11 additions & 0 deletions tests/test_verhoeff.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,14 @@ False
'1'
>>> verhoeff.is_valid('123451')
True


Non-ASCII digits (here ARABIC-INDIC DIGITs) are not valid and should be
rejected instead of being treated as the digits they look like.

>>> verhoeff.validate('\u0661\u0664\u0662\u0668\u0665\u0667\u0660')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> verhoeff.is_valid('\u0661\u0664\u0662\u0668\u0665\u0667\u0660')
False
Loading