8000 Raise InvalidComponent on unknown IBAN country · unho/python-stdnum@6b85f91 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b85f91

Browse files
committed
Raise InvalidComponent on unknown IBAN country
This partially reverts 58ea7b2. Closes arthurdejong#82
1 parent 58ea7b2 commit 6b85f91

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

stdnum/iban.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ def validate(number, check_country=True):
104104
mod_97_10.validate(number[4:] + number[:4])
105105
# look up the number
106106
info = _ibandb.info(number)
107+
if not info[0][1]:
108+
raise InvalidComponent()
107109
# check if the bban part of number has the correct structure
108110
bban = number[4:]
109-
if not _struct_to_re(info[0][1].get('bban', '-')).match(bban):
111+
if not _struct_to_re(info[0][1].get('bban', '')).match(bban):
110112
raise InvalidFormat()
111113
# check the country-specific module if it exists
112114
if check_country:

tests/test_iban.doctest

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ country code is unknown and the checksum is still valid.
3131
>>> iban.validate('0001')
3232
Traceback (most recent call last):
3333
...
34-
InvalidFormat: ...
34+
InvalidComponent: ...
35+
36+
37+
IBAN for an unknown country code.
38+
39+
>>> iban.validate('XX431234')
40+
Traceback (most recent call last):
41+
...
42+
InvalidComponent: ...
3543

3644

3745
These should all be valid numbers and are from the IBAN REGISTRY as sample

0 commit comments

Comments
 (0)
0