mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 12:45:37 +08:00
Fixed crash when textinput's default value exceeds maxLength (#24084)
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: https://github.com/facebook/react-native/pull/24084 Differential Revision: D14562719 Pulled By: cpojer fbshipit-source-id: 87ed930e35b8fa889d8b04829795fa46b7787b07
This commit is contained in:
committed by
Facebook Github Bot
parent
cd8064bc5c
commit
bbd98d5c46
@@ -373,9 +373,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_maxLength) {
|
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 we typed/pasted more than one character, limit the text inputted.
|
||||||
if (text.length > 1) {
|
if (text.length > 1) {
|
||||||
// Truncate the input string so the result is exactly maxLength
|
// Truncate the input string so the result is exactly maxLength
|
||||||
|
|||||||
Reference in New Issue
Block a user