Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,12 @@ - (NSString*)textInRange:(UITextRange*)range {
NSAssert([range isKindOfClass:[FlutterTextRange class]],
@"Expected a FlutterTextRange for range (got %@).", [range class]);
NSRange textRange = ((FlutterTextRange*)range).range;
NSAssert(textRange.location != NSNotFound, @"Expected a valid text range.");
if (textRange.location == NSNotFound) {
// Avoids [crashes](https://github.com/flutter/flutter/issues/138464) from an assertion
// against NSNotFound.
// TODO(hellohuanlin): root cause https://github.com/flutter/flutter/issues/160100
return nil;
}
// Sanitize the range to prevent going out of bounds.
NSUInteger location = MIN(textRange.location, self.text.length);
NSUInteger length = MIN(self.text.length - location, textRange.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,19 @@ - (void)testTextInRange {
XCTAssertEqual(substring.length, 0ul);
}

- (void)testTextInRangeAcceptsNSNotFoundLocationGracefully {
NSDictionary* config = self.mutableTemplateCopy;
[self setClientId:123 configuration:config];
NSArray<FlutterTextInputView*>* inputFields = self.installedInputViews;
FlutterTextInputView* inputView = inputFields[0];

[inputView insertText:@"text"];
UITextRange* range = [FlutterTextRange rangeWithNSRange:NSMakeRange(NSNotFound, 0)];

NSString* substring = [inputView textInRange:range];
XCTAssertNil(substring);
}

- (void)testStandardEditActions {
NSDictionary* config = self.mutableTemplateCopy;
[self setClientId:123 configuration:config];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ - (NSString*)textInRange:(UITextRange*)range {
NSAssert([range isKindOfClass:[FlutterTextRange class]],
@"Expected a FlutterTextRange for range (got %@).", [range class]);
NSRange textRange = ((FlutterTextRange*)range).range;
NSAssert(textRange.location != NSNotFound, @"Expected a valid text range.");
if (textRange.location == NSNotFound) {
// Avoids [crashes](https://github.com/flutter/flutter/issues/138464) from an assertion
// against NSNotFound.
// TODO(hellohuanlin): https://github.com/flutter/flutter/issues/160100
return nil;
}
return [self.text substringWithRange:textRange];
}

Expand Down
Loading