-
Notifications
You must be signed in to change notification settings - Fork 138
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
Add a nil check to prevent a crash #1120
Conversation
should the predicted text be empty string if the replacement string is nil or backedTextInputView.attributedText.string? |
Passing a replacement string of |
Summary: This is a [change](microsoft#1120) we made in our fork (React Native macOS) that we are now upstreaming to reduce the number of diffs between React Native Core and React Native macOS. Also.. one less crash �! Resolves microsoft#1679 Original PR notes: > We've seen a crash downstream where -[NSString stringByReplacingCharactersInRange:withString:] receives a nil value as the replacement string. This is not good, since we expect that argument to be non-null. > >We believe that a cause of this is that -[RCTUITextField textView:shouldChangeTextInRange:replacementString:] is being called with nil as the replacement string. (This is legal, as per [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextviewdelegate/1449325-textview?language=objc).) Right now, the only check that this delegate method does is enforcing the maxLength parameter if it exists, and changes in attributes shouldn't affect the length of the string. ## Changelog [IOS] [FIXED] - `-[RCTUITextField textView:shouldChangeTextInRange:replacementString:]` no longer crashes when we pass in a `nil` replacement string Pull Request resolved: #35941 Test Plan: Build should pass. This change has been running in our fork in production for a while so we're fairly confident of it. Reviewed By: cipolleschi Differential Revision: D42705382 Pulled By: jacdebug fbshipit-source-id: 066cd8a4ba134a681f0f4c955594b1fcda61a30e
Summary: This is a [change](microsoft#1120) we made in our fork (React Native macOS) that we are now upstreaming to reduce the number of diffs between React Native Core and React Native macOS. Also.. one less crash �! Resolves microsoft#1679 Original PR notes: > We've seen a crash downstream where -[NSString stringByReplacingCharactersInRange:withString:] receives a nil value as the replacement string. This is not good, since we expect that argument to be non-null. > >We believe that a cause of this is that -[RCTUITextField textView:shouldChangeTextInRange:replacementString:] is being called with nil as the replacement string. (This is legal, as per [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextviewdelegate/1449325-textview?language=objc).) Right now, the only check that this delegate method does is enforcing the maxLength parameter if it exists, and changes in attributes shouldn't affect the length of the string. ## Changelog [IOS] [FIXED] - `-[RCTUITextField textView:shouldChangeTextInRange:replacementString:]` no longer crashes when we pass in a `nil` replacement string Pull Request resolved: facebook#35941 Test Plan: Build should pass. This change has been running in our fork in production for a while so we're fairly confident of it. Reviewed By: cipolleschi Differential Revision: D42705382 Pulled By: jacdebug fbshipit-source-id: 066cd8a4ba134a681f0f4c955594b1fcda61a30e
Please select one of the following
Summary
We've seen a crash downstream where
-[NSString stringByReplacingCharactersInRange:withString:]
receives anil
value as the replacement string. This is not good, since we expect that argument to be non-null.We believe that a cause of this is that
-[RCTUITextField textView:shouldChangeTextInRange:replacementString:]
is being called withnil
as the replacement string. (This is legal, as per Apple's documentation.) Right now, the only check that this delegate method does is enforcing themaxLength
parameter if it exists, and changes in attributes shouldn't affect the length of the string.Changelog
[macOS] [Fixed] -
-[RCTUITextField textView:shouldChangeTextInRange:replacementString:]
no longer crashes when we pass in anil
replacement string