input-mask-ios icon indicating copy to clipboard operation
input-mask-ios copied to clipboard

Terminating app due to "Range or index out of bounds" exception

Open CFIFok opened this issue 4 years ago • 2 comments

Prerequisites

  • [x] Put an X between the brackets on this line if you have done all of the following:
    • read our Wiki;
    • read the entire Known issues section;
    • checked that my issue isn't already filled;
    • searched StackOverflow's input-mask tag for similar problems.

Describe the bug

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds' in MaskedTextFieldDelegate.swift class.

Steps to reproduce the behaviour:

  1. Create an instance of UITextField with default properties, listener (MaskedTextFieldDelegateListener) and delegate (MaskedTextFieldDelegate) 1.1. The delegate should be an instance with primaryFormat: "[000000]"(for example [000000], but it can be either [00] or [000] etc.). The main point is that it should have some kind of symbols limitation.
  2. Copy more than 6 symbols in clipboard (depend on the number of zeros in the format [000000]).
  3. Run the application and navigate to the our UITextField.
  4. Perform *three-finger gesture on the UITextField and tap Paste button (Screenshot 1) twice. The size limit should be exceeded, but everything will be ok.
  5. And finally press the Undo button (Screenshot 1).
  6. Crash!

I have made some analysis of this issue and draw conclusions which are depicted on Screenshot 2. Thank you for your cooperation in advance.

Expected behaviour The delegate should perform the undo operation, if possible, otherwise make nothing.

Actual behaviour Terminating app due to "Range or index out of bounds" exception.

Screenshots Screenshot 1 IMG_001 Screenshot 2 IMG_002

Platform information

  • OS version: iOS 13.0+
  • Library version: 6.0
  • Language: Swift 5.0
  • Device (if bug is device-specific): iPhone7\8\X

Additional context *iOS provides built-in gestures for undo, redo, copy, and paste in text views, triggered using a variety of three-finger moves – swiping left and right, or pinching in or out respectively: https://www.apple.com/ios/ios-13/features/

CFIFok avatar Apr 17 '20 14:04 CFIFok

Hey @CFIFok! Thanks a lot for you heaven-of-a-detailed cool report, things like this massively assist with debugging.

Speaking of which, we'll have an update this week with a few tweaks, and I'd like to include the fix for this bug as well.

taflanidi avatar Apr 20 '20 10:04 taflanidi

Any updates ?

alkincakiralar1996 avatar May 18 '22 10:05 alkincakiralar1996

Update is coming in 7.2.0 :D

That's a marvelous catch, thank you so much!

taflanidi avatar Apr 16 '23 14:04 taflanidi

@CFIFok mind if I add you to our contributors?

taflanidi avatar Apr 16 '23 14:04 taflanidi

Meet 7.2.0.

taflanidi avatar Apr 16 '23 15:04 taflanidi

@taflanidi yep sure! Thanx a lot too 👍