-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS] Fixes TextInput crash when undo if text longer than maxLength #45097
[iOS] Fixes TextInput crash when undo if text longer than maxLength #45097
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhongwuzw thanks for the contribution.
I'm not super familiar with the component internals, but I left a comment to get more clarity.
Also, does this work with both architectures?
if (range.location + range.length > _backedTextInputView.text.length) { | ||
range = NSMakeRange(range.location, _backedTextInputView.text.length - range.location); | ||
} else if ([newText isEqualToString:text]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be something like this?
if (range.location + range.length > _backedTextInputView.text.length) { | |
range = NSMakeRange(range.location, _backedTextInputView.text.length - range.location); | |
} else if ([newText isEqualToString:text]) { | |
if (range.location + range.length > _backedTextInputView.text.length) { | |
range = NSMakeRange(range.location, _backedTextInputView.text.length - range.location); | |
} | |
if ([newText isEqualToString:text]) { |
I'm not super familiar with the internals, but in the first branch, we are updating the range
and the second branch don't do anything related to range, so it feels weird that we have a logic that is:
// if range is greater that the backed text length
// then do something
// else if the text has not changed,
// then do something else.
the value of range and the comparison between newText
and text
are unrelated no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cipolleschi Yes, it works with both architectures.
The reason is if the range is bigger than text input's text range, we can't check whether the text changed, it may return YES
to let the system change the text input and lead to crash, instead we should skip the text equal check and replace the text input by ourself.
could you rebase on top of main, please? 🙏 |
…/fix_ipad_text_undo_crash
@cipolleschi Updated :) |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Base commit: 6bb75c7 |
@cipolleschi merged this pull request in 9b9c780. |
This pull request was successfully merged by @zhongwuzw in 9b9c780. When will my fix make it into a release? | How to file a pick request? |
Summary:
Fixes #45050 . System pass the range bigger than we allowed because we limit the maxLength. We truncated the range to fix the undo crash.
cc. @cortinico .
Changelog:
[IOS] [FIXED] - Fixes TextInput crash when undo if text longer than maxLength
Test Plan:
Repro please see #45050.