Skip to content

Accept lowercase IBANs in iban()#471

Open
sayantanmandal1 wants to merge 1 commit into
python-validators:masterfrom
sayantanmandal1:iban-accept-lowercase
Open

Accept lowercase IBANs in iban()#471
sayantanmandal1 wants to merge 1 commit into
python-validators:masterfrom
sayantanmandal1:iban-accept-lowercase

Conversation

@sayantanmandal1

Copy link
Copy Markdown

iban() treats lowercase input as well-formed (the regex has re.IGNORECASE and
[a-z0-9]) but then rejects it:

iban("GB82WEST12345698765432")  # True
iban("gb82west12345698765432")  # False, same IBAN

_char_value scores letters with 10 + ord(char) - ord("A"), which is only right
for uppercase, so lowercase letters get the wrong value and the mod-97 check
fails.

Upper-casing the char before scoring it fixes this. It only lets through inputs
that were already valid IBANs, so nothing that passed before changes. Added
lowercase and mixed-case cases to the tests.

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.

1 participant