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

fix: Calculate length of posts and polls with emojis correctly #315

Merged
merged 3 commits into from
Dec 12, 2023

Conversation

nikclayton
Copy link
Contributor

Mastodon counts post lengths by considering emojis to be single characters, no matter how many unicode code points they are composed of. So "😜" has length 1.

Pachli was using String.length, which considers "😜" as length 2.

Correct the calculation by using a BreakIterator to count the characters in the string, which treats multi-character emojis as a length 1.

Poll options had a similar problem, exacerbated by the Mastodon web UI also having the same problem, see mastodon/mastodon#28336.

Fix that by creating MastodonLengthFilter, an InputFilter that does the right thing for regular text that may contain emojis.

See also tuskyapp/Tusky#4152, which has the fix for status length but not polls.

nikclayton and others added 3 commits December 12, 2023 14:32
Mastodon counts post lengths by considering emojis to be single
characters, no matter how many unicode code points they are composed
of. So "😜" has length 1.

Pachli was using `String.length`, which considers "😜" as length 2.

Correct the calculation by using a BreakIterator to count the characters
in the string, which treats multi-character emojis as a length 1.

Poll options had a similar problem, exacerbated by the Mastodon web UI
also having the same problem, see mastodon/mastodon#28336.

Fix that by creating `MastodonLengthFilter`, an `InputFilter` that does
the right thing for regular text that may contain emojis.

See also tuskyapp/Tusky#4152, which has the fix
for status length but not polls.

Co-authored-by: Konrad Pozniak <opensource@connyduck.at>
Removes the need for a synthetic accessor
@nikclayton nikclayton merged commit 098983f into pachli:main Dec 12, 2023
5 checks passed
@nikclayton nikclayton deleted the count-emojis branch December 13, 2023 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant