EmbarkStudios / discord-sdk

An open implementation of the Discord Game SDK in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improper truncation of UTF-8 strings in `discord_sdk::activity::truncate`

Friz64 opened this issue · comments

thread 'main' panicked at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/string.rs:1396:13:
assertion failed: self.is_char_boundary(new_len)
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: core::panicking::panic
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:144:5
   3: discord_sdk::activity::truncate::{{closure}}
   4: discord_sdk::activity::ActivityBuilder::details

if text.len() > 128 {
tracing::warn!("{} '{}' is too long and will be truncated", name, text);
text.truncate(128);
}

To Reproduce
Steps to reproduce the behavior:

  1. Call discord_sdk::activity::ActivityBuilder::default().details("xäääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääää")