Skip to content
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

[Clipboard] Assert at least one clipboard data variant is provided #122446

Merged
merged 1 commit into from Mar 24, 2023

Conversation

loic-sharma
Copy link
Member

@loic-sharma loic-sharma commented Mar 11, 2023

This change makes the clipboard require at least one clipboard data variant. Today, this effectively makes ClipboardData.text required as it is the only data variant supported by Clipboard. This is a breaking change.

Part of #121976

Background

Currently the different platforms behave unexpectedly if you set your clipboard text to null:

  1. Android and iOS will set your clipboard content to the text "null".
  2. Web assumes incorrectly that the text is non-null
  3. Linux will return an error if the text is null
  4. Windows crashes: Clipboard.setData crashes the app #121976

In other words, customers who set their clipboard to null today are broken. Instead, they should set their clipboard's text to the empty string "".

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.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Mar 11, 2023
@loic-sharma loic-sharma force-pushed the you_shall_not_pass_null branch 3 times, most recently from 4a5b89a to 45518bb Compare March 18, 2023 21:49
@loic-sharma loic-sharma marked this pull request as ready for review March 18, 2023 23:47
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@loic-sharma loic-sharma changed the title Disallow setting the clipboard to null [Clipboard] Assert at least one clipboard data variant is provided Mar 18, 2023
Copy link
Contributor

@yaakovschectman yaakovschectman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bernaferrari
Copy link
Contributor

I don't like the assert, wouldn't something like "text must not be null" be simpler? There are no other variants right now, it isn't clear.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@loic-sharma
Copy link
Member Author

@bernaferrari Thanks for the feedback, I agree that the previous assertion message was unclear. This should be addressed now, let me know if you have additional comments!

@bernaferrari
Copy link
Contributor

Maaaaybe I would mention in the comment "eventually with unions this won't be nullable anymore" or something like this, because in a few years when someone implements union in Dart, someone could possibly just search the codebase and update. Maybe.

Just an idea.

@loic-sharma
Copy link
Member Author

@bernaferrari The clipboard can contain different content for different formats.
For example, a clipboard can contain both an image and the link to the image.
The app that pastes the clipboard can choose from these different contents
depending on what it supports. It's not clear that a union would be a good fit
for these kinds of scenarios.

@bernaferrari
Copy link
Contributor

That's fair.. I was thinking text only.

@loic-sharma loic-sharma force-pushed the you_shall_not_pass_null branch 2 times, most recently from d251c0a to 629e72f Compare March 21, 2023 18:57
Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - and thanks for the detailed notes on the current broken behaviour when this is null. If you haven't already, make sure this gets added to the release notes.

loic-sharma added a commit to loic-sharma/flutter-devtools that referenced this pull request Mar 22, 2023
Flutter behaves unexpectedly if you set your clipboard text to null:

1. Android and iOS will set your clipboard content to the text "null".
2. Linux and web throws
3. Windows crashes

Flutter will be updated to disallow setting the clipboard text to null: flutter/flutter#122446

Part of flutter/flutter#121976
loic-sharma added a commit to flutter/devtools that referenced this pull request Mar 24, 2023
Flutter behaves unexpectedly if you set your clipboard text to null:

1. Android and iOS will set your clipboard content to the text "null".
2. Linux and web throws
3. Windows crashes

Flutter will be updated to disallow setting the clipboard text to null: flutter/flutter#122446

Part of flutter/flutter#121976
This change makes the clipboard require at least one clipboard data variant.
Today, this effectively makes `ClipboardData.text` required as it is the
only data variant supported by `Clipboard`. This is a breaking change.

Part of flutter#121976
@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 24, 2023
@auto-submit auto-submit bot merged commit 70e1dc7 into flutter:master Mar 24, 2023
72 checks passed
@bernaferrari
Copy link
Contributor

The name of the branch 😂

image

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 25, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
@loic-sharma loic-sharma deleted the you_shall_not_pass_null branch June 26, 2023 17:19
auto-submit bot pushed a commit that referenced this pull request Jun 27, 2023
#122446 was a breaking change in Flutter 3.10 that made the `ClipboardData` constructor's `text` argument a required non-nullable argument. This leverages `dart fix`'s new automatic migration to, well, automatically migrate affected users.

Manual migration docs: https://docs.flutter.dev/release/breaking-changes/clipboard-data-required

Follow-up to #122446
Part of #121976
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants