stripe / stripe-ios

Stripe iOS SDK
https://stripe.com
MIT License
2.12k stars 982 forks source link

Fatal error: Can't take a prefix of negative length from a collection #1907

Closed buhikon closed 2 years ago

buhikon commented 2 years ago

Summary

A crash occurred on STPFormTextField

Code to reproduce

  1. Launch a sample called UI Examples on iPad (device or simulator)
  2. Select the first cell (Card Field) from the table view on the main screen
  3. (a new view controller will be displayed, and a credit card text field will be automatically focused and a keyboard will appear)
  4. Tap a space bar in the keyboard
  5. Tap a backspace in the keyboard
  6. (crash)

iOS version

15.1

Installation method

Tested on the sample app

SDK version

21.9.0

Other information

(STPFormTextField.swift)

404        if deleting {
405            if let sanitized = unformattedString(for: textField.text) {
406                inputText = sanitized.stp_safeSubstring(to: sanitized.count - 1)
407            }
408        } else {

when the crash happens,

ramont-stripe commented 2 years ago

@buhikon thank you for reporting this issue! I was able to reproduce it by following the provided steps. We are working on a fix for this.

ramont-stripe commented 2 years ago

Hi @buhikon,

We just released a fix for this in v21.10.0. I'm closing this issue for now; feel free to re-open it if you are still experiencing this issue after upgrading.

Thank you again for reporting this and providing very detailed steps on how to reproduce it!