Skip to content

Conversation

@dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented May 26, 2022

This PR fixes the confusion raised in #104578 by checking TextRange against the string content and report errors. This PR also fixes a bug found by this change on the conversion between TextInputAction and string.

Users might construct invalid TextRanges and send them to the engine. These errors will not be caught during construction, because TextEditingValue is a const class and can't verify TextRange'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 toJSON and fromJSON. 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 try block and reports errors to FlutterErrors.report. This is possible because we expect no errors from textinput'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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@dkwingsmt dkwingsmt requested a review from keyonghan as a code owner May 26, 2022 13:25
@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation engine flutter/engine related. See also e: labels. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels. labels May 26, 2022
@dkwingsmt dkwingsmt force-pushed the verify-text-range-and-fail-loudly branch from c948e2b to a0a6629 Compare May 26, 2022 13:30
@dkwingsmt dkwingsmt removed the request for review from keyonghan May 26, 2022 13:30
@dkwingsmt dkwingsmt changed the title TextInput: Errors during method call fails loudly TextInput: Verify TextRange and make method call fail loudly May 26, 2022
@dkwingsmt dkwingsmt requested a review from justinmc May 26, 2022 13:39
@dkwingsmt dkwingsmt added a: error message Error messages from the Flutter framework and removed c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels. engine flutter/engine related. See also e: labels. f: material design flutter/packages/flutter/material repository. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation labels May 26, 2022
@dkwingsmt dkwingsmt force-pushed the verify-text-range-and-fail-loudly branch from e2a0ffa to b1c806b Compare June 6, 2022 16:35
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Linux web_tests_6 has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux web_canvaskit_tests_3 has failed. Please fix the issues identified (or deflake) before re-applying this label.

this.selection = const TextSelection.collapsed(offset: -1),
this.composing = TextRange.empty,
}) : assert(text != null),
// The constructor does not verified that `selection` and `composing` are
Copy link
Contributor

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".

@dkwingsmt dkwingsmt requested a review from dnfield June 13, 2022 23:40
_channel.invokeMethod<void>(
'TextInput.setClient',
<dynamic>[ connection._id, configuration.toJson() ],
<dynamic>[
Copy link
Contributor

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).

Copy link
Contributor

@dnfield dnfield left a 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.

@dnfield
Copy link
Contributor

dnfield commented Jun 14, 2022

This may have broken web?

@dkwingsmt dkwingsmt mentioned this pull request Jun 14, 2022
8 tasks
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Linux fuchsia_precache has failed. Please fix the issues identified (or deflake) before re-applying this label.

@dkwingsmt dkwingsmt merged commit 576e85c into flutter:master Jun 15, 2022
@dkwingsmt dkwingsmt deleted the verify-text-range-and-fail-loudly branch June 15, 2022 03:31
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
…#104711)

* Fix

* Tests

* Format

* Empty line

* Fix range test

* Fix

* Comments

* trailing spaces

* Fix tests

* Comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: error message Error messages from the Flutter framework a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants