-
Notifications
You must be signed in to change notification settings - Fork 29.7k
fix_emoji_crash #31468
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
fix_emoji_crash #31468
Conversation
|
I've tried this locally on an iPhone 8. I can't seem to get the cursor to land in the middle of an emoji as you're showing here. What version of Flutter are you using? I'm on master. |
|
Scratch that - I managed to reproduce it with some dragging around. With a rainbow flag emoji, there was no crash (but I did end up with a separate rainbow and flag character :D). With a two code point emoji (one of the smiley faces), it crashed. |
|
This actually is hitting on multiple bugs - /cc @justinmc @GaryQian @goderbauer who have all been involved in things related to this.
Right now I think a higher priority is to fix the crash on the engine side. |
| assert(isNormalized); | ||
| if(text.isNotEmpty && start > 0 && start < text.length ){ | ||
| final int startCodeUnit = text.codeUnitAt(start); | ||
| if( startCodeUnit & 0x8C00 == 0x8C00 ){ |
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.
What happens if we're in a multi-byte character that has more than two bytes? e.g. the rainbow flag emoji is four codepoints:
🏳 U+1F3F3
️ U+FE0F
U+200D
🌈 U+1F308
In testing this issue, I was able to successfully land inside those codepoints, type a character, and split the flag into a blank flag with a rainbow. I don't think this logic would fix that scenario.
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.
main() {
String a='🌈';
print(a.codeUnits.map((v)=> v.toRadixString(16)));
}
result is (d83c, df08), two characters, same as '𐐷'.
flutter using UTF-16 to handle character,
You can read the wikipedia carefully, only 2 cases, one case is 2 bytes, and the other case is 4 bytes. In flutter, it is 1 character and 2 characters. There are no other situations.
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.
I am so sorry, I'm wrong.
Multi-byte characters do exist, like :
👨👩👧 (U+1F468, U+200D, U+1F469, U+200D, U+1F467)
🇨🇳 (U+1F1E8, U+1F1F3)
Above code is not working.
I am try to find a new way.
|
See #30851 (comment) for the iOS stack trace |
|
Crash is due to iOS not tolerating invalid UTF-8 code sequence when decoding or encoding JSON. Looking to see if we can make platform side more resilient (Android already handles this better). We should definitely fix this on the framework side too. |
Doctor summary (to see all details, run flutter doctor -v): [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) |
|
“make sure the cursor be NOT able to land in the middle of an emoji.” is better, |
|
I'm going to close this in favor of flutter/engine#8747 Thanks for your help in diagnosing this issue! |
Description
fix in iOS paste emoji crash
1 Test code
environment

device:iOS 12 ,iPhone
keyboard setting : english & emoji
analyze
https://en.wikipedia.org/wiki/UTF-16 @dnfield one character may be two code units.
try this code,
Related Issues
Replace this paragraph with a list of issues related to this PR from our issue database. Indicate, which of these issues are resolved or fixed by this PR.
Tests
I added the following tests:
Replace this with a list of the tests that you added as part of this PR. A change in behaviour with no test covering it
will likely get reverted accidentally sooner or later. PRs must include tests for all changed/updated/fixed behaviors. See Test Coverage.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?