Exception when composing IBANs where the check digits have a leading zero
trustlydaniel opened this issue · 1 comments
trustlydaniel commented
Check digits can have leading zeroes, Modulo97#calculateCheckDigits
returns an int so the value needs to be left padded if size is less than two.
Example (IBAN in example is generated, not a real bank account):
public class CheckDigitsLeadingZeroExample {
public static void main(String[] args) {
String bban = "50516227620311";
IBAN iban = IBAN.compose("DK", bban);
//Expected iban: DK0350516227620311
//throws: Input failed length validation: found 17, but expect 18 for country code.
String input = "DK0050516227620311";
int checkDigits = Modulo97.calculateCheckDigits(input);
// checkDigits is 3
}
}
barend commented
Hi @trustlydaniel,
Thanks! That's a good catch. The error is quite glaring once you see it, but I have missed it all these years 😬
Thanks also for providing #93 to fix it. Much appreciated.
Cheers,
Barend