Issue Description
Tapping "Undo" button will result in application crashing.
Steps to Replicate
A Ti.UI.Textfield that will only allow numeric characters (0 to 9 and .) Textfiled has keyboard type of Ti.UI.KEYBOARD_DECIMAL_PAD.
1. Started the application.
2. Tapping on numbers will update the textfield and tapping on undo will clear the textfield (This is expected behaviour).
3. Tapping on other characters present on the keyboard that are not numeric and then tapping on the undo button will result in application crashing.
Test Case
var changeCallback = function(e) {
e.source.value = e.source.value.replace(new RegExp("[^0-9.]"), "");
};
var window = Ti.UI.createWindow({
layout : 'vertical',
backgroundColor : 'white',
height : Ti.UI.FILL,
width : Ti.UI.FILL
});
var sampleTest = Ti.UI.createTextField({
height : 40,
width : Titanium.UI.FILL,
keyboardType : Ti.UI.KEYBOARD_DECIMAL_PAD,
top : 50,
left : 50,
borderWidth : 1,
borderColor : "blue",
maxLength : 53,
hintText : 'Here goes the sample text',
value : '',
});
sampleTest.addEventListener("change", changeCallback);
window.add(sampleTest);
window.open();
Crash logs
-- Start application log -----------------------------------------------------
[INFO] dropDown/1.0 (4.2.0.afcd782)
[ERROR] The application has crashed with an uncaught exception 'NSRangeException'.
[ERROR] Reason:
[ERROR] -[__NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds
[ERROR] Stack trace:
[ERROR]
[ERROR] 0 CoreFoundation 0x0000000185d3a530 <redacted> + 132
[ERROR] 1 libobjc.A.dylib 0x0000000196cf80e4 objc_exception_throw + 60
[ERROR] 2 CoreFoundation 0x0000000185d3a470 <redacted> + 0
[ERROR] 3 CoreFoundation 0x0000000185ce4ed0 <redacted> + 256
[ERROR] 4 Foundation 0x0000000186c2dec4 <redacted> + 160
[ERROR] 5 dropDown 0x000000010014cf30 dropDown + 429872
[ERROR] 6 UIKit 0x000000018ac9beec <redacted> + 112
[ERROR] 7 UIKit 0x000000018aca1760 <redacted> + 108
[ERROR] 8 UIKit 0x000000018acfcae8 <redacted> + 268
[ERROR] 9 Foundation 0x0000000186c75960 <redacted> + 308
[ERROR] 10 Foundation 0x0000000186c74584 <redacted> + 468
[ERROR] 11 UIKit 0x000000018a712030 <redacted> + 640
[ERROR] 12 UIKit 0x000000018a711ca0 <redacted> + 644
[ERROR] 13 UIKit 0x000000018a705db4 <redacted> + 3784
[ERROR] 14 UIKit 0x000000018a704d48 <redacted> + 1428
[ERROR] 15 UIKit 0x000000018a7046d0 <redacted> + 252
[ERROR] 16 UIKit 0x000000018a570630 <redacted> + 388
[ERROR] 17 UIKit 0x000000018a700e3c <redacted> + 272
[ERROR] 18 UIKit 0x000000018a700bf4 <redacted> + 392
[ERROR] 19 UIKit 0x000000018a57c03c <redacted> + 700
[ERROR] 20 UIKit 0x000000018a575590 <redacted> + 684
[ERROR] 21 UIKit 0x000000018a548e60 <redacted> + 264
[ERROR] 22 UIKit 0x000000018a7e846c <redacted> + 15220
[ERROR] 23 UIKit 0x000000018a5473d0 <redacted> + 1716
[ERROR] 24 CoreFoundation 0x0000000185cf2d34 <redacted> + 24
[ERROR] 25 CoreFoundation 0x0000000185cf1fd8 <redacted> + 264
[ERROR] 26 CoreFoundation 0x0000000185cf0088 <redacted> + 712
[ERROR] 27 CoreFoundation 0x0000000185c1d1f4 CFRunLoopRunSpecific + 396
[ERROR] 28 GraphicsServices 0x000000018ef3f6fc GSEventRunModal + 168
[ERROR] 29 UIKit 0x000000018a5ae10c UIApplicationMain + 1488
[ERROR] 30 dropDown 0x00000001000ebbec dropDown + 31724
[ERROR] 31 libdyld.dylib 0x0000000197376a08 <redacted> + 4
[ERROR] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds'
[ERROR] *** First throw call stack:
[ERROR] (0x185d3a530 0x196cf80e4 0x185d3a470 0x185ce4ed0 0x186c2dec4 0x10014cf30 0x18ac9beec 0x18aca1760 0x18acfcae8 0x186c75960 0x186c74584 0x18a712030 0x18a711ca0 0x18a705db4 0x18a704d48 0x18a7046d0 0x18a570630 0x18a700e3c 0x18a700bf4 0x18a57c03c 0x18a575590 0x18a548e60 0x18a7e846c 0x18a5473d0 0x185cf2d34 0x185cf1fd8 0x185cf0088 0x185c1d1f4 0x18ef3f6fc 0x18a5ae10c 0x1000ebbec 0x197376a08)
[link](http://stackoverflow.com/questions/433337/set-the-maximum-character-length-of-a-uitextfield) explaining crash. Likely have a solution to prevent crash, but will set 'undo' to *not* clear the textfield, which should be reasonable considering that 'undo' isn't really a designated function for any keyboard numerical pad.
PR here: https://github.com/appcelerator/titanium_mobile/pull/6975 Only merge after 4.2.0
CR passed and merged to master.
Verified fixed, using: MacOS 10.11 (15A263e) Studio 5.0.0.201508271032 Ti SDK 5.0.0.v20150827102632 Appc NPM 4.2.0-1 Appc CLI 5.0.0-24 Ti CLI 4.1.5 Alloy 1.7.5 Arrow 1.2.48 Xcode 7.0 (7A192o) Node v0.10.37 Java 1.7.0_45 preproduction I do not encounter a crash when removing non-numerical characters.