Skip to content

fix(messaging): split Telegram and Twitch messages on char boundaries - #662

Open
RaphaelFakhri wants to merge 1 commit into
spacedriveapp:mainfrom
RaphaelFakhri:fix/telegram-twitch-split-utf8
Open

RaphaelFakhri wants to merge 1 commit into
spacedriveapp:mainfrom
RaphaelFakhri:fix/telegram-twitch-split-utf8

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Summary

  • split_message in the Telegram and Twitch adapters slices replies at a fixed byte index (remaining[..max_len]).
  • When a multibyte UTF-8 character spans that index, the slice panics with byte index N is not a char boundary, and the reply is never delivered.
  • The Discord, Slack, and Mattermost copies of split_message already clamp to a char boundary (fix: prevent panic in split_message on multibyte UTF-8 char boundaries #49). The Telegram and Twitch copies did not get the same fix.

Fix

Clamp the search window to the nearest char boundary at or before max_len with str::floor_char_boundary, the same helper used elsewhere in the codebase, before looking for a newline or space to split on.

Testing

  • Adds split_message_respects_multibyte_char_boundaries to the Telegram tests and a new test module in the Twitch adapter.
  • Before the fix, both tests panic with byte index 5 is not a char boundary. After the fix, both pass.
  • cargo fmt --all -- --check and cargo clippy --lib --tests -- -Dwarnings pass.

Fixes #661

This branch has not been deployed

No deployments
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.

Telegram and Twitch adapters panic when splitting long messages with multibyte characters

1 participant