From 58ea7b20682021e9ed91587adb484534fb7a768f Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Tue, 9 Oct 2018 22:07:33 +0200 Subject: Fix issue with minimal IBAN This ensures that an IBAN with a missing bban part and unknown country code (while still having a valid MOD 97,10 checksum) is considered valid. Closes https://github.com/arthurdejong/python-stdnum/issues/84 --- stdnum/iban.py | 2 +- tests/test_iban.doctest | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/stdnum/iban.py b/stdnum/iban.py index 09c8fdb..bbf181b 100644 --- a/stdnum/iban.py +++ b/stdnum/iban.py @@ -106,7 +106,7 @@ def validate(number, check_country=True): info = _ibandb.info(number) # check if the bban part of number has the correct structure bban = number[4:] - if not _struct_to_re(info[0][1].get('bban', '')).match(bban): + if not _struct_to_re(info[0][1].get('bban', '-')).match(bban): raise InvalidFormat() # check the country-specific module if it exists if check_country: diff --git a/tests/test_iban.doctest b/tests/test_iban.doctest index eef1948..0625fb1 100644 --- a/tests/test_iban.doctest +++ b/tests/test_iban.doctest @@ -25,6 +25,15 @@ really useful as module documentation. >>> from stdnum import iban +Test for IBAN corner case that happens when the bban part is empty, the +country code is unknown and the checksum is still valid. + +>>> iban.validate('0001') +Traceback (most recent call last): + ... +InvalidFormat: ... + + These should all be valid numbers and are from the IBAN REGISTRY as sample numbers: -- cgit v1.2.3