Skip to content

Commit

Permalink
Fixed crash when textinput's default value exceeds maxLength (#24084)
Browse files Browse the repository at this point in the history
Summary:
Bug comes from #23545, if `allowedLength < 0`, it would crash if `text.length > 1`.

cc. cpojer

[iOS] [Fixed] - Fixed crash when textinput's default value exceeds maxLength
Pull Request resolved: #24084

Differential Revision: D14562719

Pulled By: cpojer

fbshipit-source-id: 87ed930e35b8fa889d8b04829795fa46b7787b07
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Mar 22, 2019
1 parent cd8064b commit bbd98d5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Libraries/Text/TextInput/RCTBaseTextInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin
}

if (_maxLength) {
NSInteger allowedLength = _maxLength.integerValue - backedTextInputView.attributedText.string.length + range.length;
NSInteger allowedLength = MAX(_maxLength.integerValue - (NSInteger)backedTextInputView.attributedText.string.length + (NSInteger)range.length, 0);

if (allowedLength < 0 || text.length > allowedLength) {
if (text.length > allowedLength) {
// If we typed/pasted more than one character, limit the text inputted.
if (text.length > 1) {
// Truncate the input string so the result is exactly maxLength
Expand Down

0 comments on commit bbd98d5

Please sign in to comment.