Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-5891

Parsing of ChinUnionPay credit card should use the first 6 characters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 6.19.0
    • 6.20.0, 7.0.0-M6
    • wicket
    • None

    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

      { 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).

      Attachments

        Activity

          People

            mgrigorov Martin Tzvetanov Grigorov
            mgrigorov Martin Tzvetanov Grigorov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: