Description
User report:
A China UnionPay number has to start with 622 (622126-622925) and has to have a length between 16 and 19. The source code of CreditCardValidator is:
220 private boolean isChinaUnionPay(String creditCardNumber)
221 {
222 cardId = CreditCardValidator.INVALID;
223 boolean returnValue = false;
224
225 if ((creditCardNumber.length() >= 16 && creditCardNumber.length() <= 19) &&
226 (creditCardNumber.startsWith("622")))
227 {
228 int firstDigits = Integer.parseInt(creditCardNumber.substring(0, 5));
229 if (firstDigits >= 622126 && firstDigits <= 622925)
230
234 }
235
236 return returnValue;
237 }
The problem is on the line 228 because the substring returns the first 5 digits and it is compared to 6 digits, so "firstDigits" is always < than 622126. The fix is to do #substring(0, 6).