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: 1 addition & 1 deletion stdnum/iso6346.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from stdnum.util import clean


_iso6346_re = re.compile(r'^\w{3}(U|J|Z|R)\d{7}$')
_iso6346_re = re.compile(r'^[A-Z]{3}(U|J|Z|R)[0-9]{7}$')


def compact(number: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion stdnum/pt/cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from stdnum.util import clean


_cc_re = re.compile(r'^\d*[A-Z0-9]{2}\d$')
_cc_re = re.compile(r'^[0-9]*[A-Z0-9]{2}[0-9]$')


def compact(number: str) -> str:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_iso6346.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ False
Traceback (most recent call last):
...
InvalidFormat: ...


Letters and digits outside of the ASCII range are not valid and should be
rejected with a validation error instead of crashing.

>>> iso6346.is_valid('CSQU٣054383')
False
>>> iso6346.is_valid('CSÉU3054383')
False
>>> iso6346.is_valid('CS_U3054383')
False
>>> iso6346.validate('CSQU٣054383')
Traceback (most recent call last):
...
InvalidFormat: ...
13 changes: 13 additions & 0 deletions tests/test_pt_cc.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ These have been found online and should all be valid numbers.
... '''
>>> [x for x in numbers.splitlines() if x and not cc.is_valid(x)]
[]


Non-ASCII digits are not valid and should be rejected with a validation
error instead of crashing.

>>> cc.is_valid('00000000 ٠ ZZ4')
False
>>> cc.is_valid('٠٠٠٠٠٠٠٠٠ZZ4')
False
>>> cc.validate('00000000 ٠ ZZ4')
Traceback (most recent call last):
...
InvalidFormat: ...
Loading