Titanium JIRA Archive
Appcelerator Community (AC)

[AC-762] Unhanded exception 'NSRangeException' when Undo key is pressed on iOS numeric keyboard

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2014-04-06T05:57:44.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsios
ReporterGoran Krstevski
AssigneeRitu Agrawal
Created2014-03-21T12:47:58.000+0000
Updated2016-03-08T07:37:01.000+0000

Description

I have TextArea control which accept only decimal numeric values. Inserted value is validate on 'change' event and if it is not valid then value of TextArea is set to last valid string. In case when not valid character is inserted and then UNDO key is pressed on numeric iOS keyboard, application crashed with following message: [ERROR] The application has crashed with an uncaught exception 'NSRangeException'.(check attachment for more info) Steps to reproduce on Test case : 1. Press on Text area in the middle of the screen in order to change focus on it 2. When keyboard is opened press on some symbol(e.g. "@" ), text area should be empty 3. Press on "Undo" key on keyboard => Application will crash

Attachments

FileDateSize
app.js2014-03-24T09:50:00.000+0000760
log2014-03-21T12:47:58.000+00004299
Screen Shot 2014-03-26 at 9.11.58 AM.png2014-03-26T08:20:09.000+000067339

Comments

  1. Ritu Agrawal 2014-03-21

    Thanks for attaching the log file but to evaluate further we need a simple runnable test case. Can you please attach the same?
  2. Goran Krstevski 2014-03-24

    Test case attached.
  3. Ritu Agrawal 2014-03-25

    This appears to be a test case issue. You are using a keyboard that supports only numeric characters. If you type in numeric characters and then undo, everything works fine and there is no crash. If you type in a symbol using your computer as numeric keyboard does not support this character, you are stripping this symbol in test case and setting the numeric value so undo becomes invalid at this point and causes program to malfunction.
               var val = textArea.value;
               Ti.API.info("val = " + val);
               val = val.replace(/[^\d\.\,]/g, "");
               val = val.replace(/,/g, '.');
               Ti.API.info("Modified val = " + val);
               textArea.setValue(val);
       
       Output:
       [INFO] :   val = 1
       [INFO] :   Modified val = 1
       [INFO] :   val = 12
       [INFO] :   Modified val = 12
       [INFO] :   val = 123
       [INFO] :   Modified val = 123
       [INFO] :   val = 123@
       [INFO] :   Modified val = 123
       [INFO] :   val = 123@
       [INFO] :   Modified val = 123
       
  4. Goran Krstevski 2014-03-25

    But it is not expect application to crash when user accidentally press on a valid buttons on the keyboard.
  5. Ritu Agrawal 2014-03-26

    Can you please explain how the user is going to type a symbol on a numeric keypad?
  6. Goran Krstevski 2014-03-26

    Please check screenshot in attachment.
  7. Ritu Agrawal 2014-03-27

    Thanks. The issue here is that you are modifying the user entered value dynamically. For example, if a user types "123@" then you are replacing it with "123" and that string is shorter than the user typed string. Undo Manager tries to undo 4 characters and finds only 3 characters and throws out of range exception. You should either not modify the string or replace an undesired character with space.

JSON Source