-
Notifications
You must be signed in to change notification settings - Fork 29.7k
TextInput: Verify TextRange and make method call fail loudly #104711
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
TextInput: Verify TextRange and make method call fail loudly #104711
Conversation
c948e2b to
a0a6629
Compare
e2a0ffa to
b1c806b
Compare
|
This pull request is not suitable for automatic merging in its current state.
|
| this.selection = const TextSelection.collapsed(offset: -1), | ||
| this.composing = TextRange.empty, | ||
| }) : assert(text != null), | ||
| // The constructor does not verified that `selection` and `composing` are |
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.
Grammar nit: "does not verify".
| _channel.invokeMethod<void>( | ||
| 'TextInput.setClient', | ||
| <dynamic>[ connection._id, configuration.toJson() ], | ||
| <dynamic>[ |
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.
consider <Object> (or nullable if needed).
dnfield
left a comment
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.
LGTM with nit(s)
Please either leave the original bug open or file a new one to fix the embedding. We should not allow engine crashes on invalid input from applications, and applications are not required to use the framework for this.
|
This may have broken web? |
|
This pull request is not suitable for automatic merging in its current state.
|
…#104711) * Fix * Tests * Format * Empty line * Fix range test * Fix * Comments * trailing spaces * Fix tests * Comments
This PR fixes the confusion raised in #104578 by checking
TextRangeagainst the string content and report errors. This PR also fixes a bug found by this change on the conversion betweenTextInputActionand string.Users might construct invalid
TextRanges and send them to the engine. These errors will not be caught during construction, becauseTextEditingValueis a const class and can't verifyTextRange's fields. This might result in silent crashes on the engine side.To catch this on the framework side, I tried to add verification to
toJSONandfromJSON. However, this is not sufficient. The error can occur during a method call handler, where errors are swallowed and converted to an error reply to the method call. Unsurprisingly, the engine side doesn't handle errors. Even if it does, the error would be very hard to track due to lack of stacktrace.Therefore, this PR also wraps method call handlers with a
tryblock and reports errors toFlutterErrors.report. This is possible because we expect no errors fromtextinput's handlers.I would suggest making all errors during method call handlers reported in the same way. However that would be out of the scope of this PR.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.