Skip to content

Commit

Permalink
Fix iOS keyboard crash (#10656)
Browse files Browse the repository at this point in the history
Fixes an iOS crash on physical devices in `-[__NSCFString substringWithRange:]`: range out of bounds. According to Apple's docs for `UITextInput` method `positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset`, this method should return:

A custom UITextPosition object that represents the location in a document that is at the specified offset from position. Return nil if the computed text position is less than 0 or greater than the length of the backing string.
  • Loading branch information
Qxyat authored and cbracken committed Aug 12, 2019
1 parent a50ec07 commit e95125a
Showing 1 changed file with 6 additions and 0 deletions.
Expand Up @@ -433,6 +433,12 @@ - (NSUInteger)incrementOffsetPosition:(NSUInteger)position {

- (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {
NSUInteger offsetPosition = ((FlutterTextPosition*)position).index;

NSInteger newLocation = (NSInteger)offsetPosition + offset;
if (newLocation < 0 || newLocation > (NSInteger)self.text.length) {
return nil;
}

if (offset >= 0) {
for (NSInteger i = 0; i < offset && offsetPosition < self.text.length; ++i)
offsetPosition = [self incrementOffsetPosition:offsetPosition];
Expand Down

0 comments on commit e95125a

Please sign in to comment.