Martin Grigorov created WICKET-5891: ---------------------------------------
Summary: Parsing of ChinUnionPay credit card should use the first 6 characters Key: WICKET-5891 URL: https://issues.apache.org/jira/browse/WICKET-5891 Project: Wicket Issue Type: Bug Components: wicket Affects Versions: 6.19.0 Reporter: Martin Grigorov Assignee: Martin Grigorov 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 { 231 cardId = CreditCardValidator.CHINA_UNIONPAY; 232 returnValue = true; 233 } 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). -- This message was sent by Atlassian JIRA (v6.3.4#6332)