Skip to content

Commit 2db8487

Browse files
committed
Fix truncation when using FixedString<u8> where multibyte characters push over the limit (serenity-rs#2660)
1 parent 1526f9b commit 2db8487

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

src/model/application/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ pub struct Command {
5454
/// ([source](https://discord.com/developers/docs/interactions/application-commands#retrieving-localized-commands)).
5555
pub name_localizations: Option<HashMap<String, String>>,
5656
/// The command description.
57-
pub description: FixedString<u8>,
57+
pub description: FixedString<u16>,
5858
/// The localized command description of the selected locale.
5959
///
6060
/// If the description is localized, either this field or [`Self::description_localizations`]
6161
/// is set, depending on which endpoint this data was retrieved from
6262
/// ([source](https://discord.com/developers/docs/interactions/application-commands#retrieving-localized-commands)).
63-
pub description_localized: Option<FixedString<u8>>,
63+
pub description_localized: Option<FixedString<u16>>,
6464
/// All localized command descriptions.
6565
///
6666
/// If the description is localized, either this field or [`Self::description_localized`] is

src/model/application/component.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub struct InputText {
247247
#[serde(rename = "type")]
248248
pub kind: ComponentType,
249249
/// Developer-defined identifier for the input; max 100 characters
250-
pub custom_id: FixedString<u8>,
250+
pub custom_id: FixedString<u16>,
251251
/// The [`InputTextStyle`]. Required when sending modal data.
252252
///
253253
/// Discord docs are wrong here; it says the field is always sent in modal submit interactions
@@ -276,7 +276,7 @@ pub struct InputText {
276276
pub value: Option<FixedString<u16>>,
277277
/// Custom placeholder text if the input is empty; max 100 characters
278278
#[serde(skip_serializing_if = "Option::is_none")]
279-
pub placeholder: Option<FixedString<u8>>,
279+
pub placeholder: Option<FixedString<u16>>,
280280
}
281281

282282
enum_number! {

src/model/channel/channel_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,11 @@ impl ChannelId {
531531
/// # Errors
532532
///
533533
/// Same as [`Self::to_channel()`].
534-
pub async fn name(self, cache_http: impl CacheHttp) -> Result<FixedString<u8>> {
534+
pub async fn name(self, cache_http: impl CacheHttp) -> Result<String> {
535535
let channel = self.to_channel(cache_http).await?;
536536

537537
Ok(match channel {
538-
Channel::Guild(channel) => channel.name,
538+
Channel::Guild(channel) => channel.name.into(),
539539
Channel::Private(channel) => channel.name(),
540540
})
541541
}

src/model/channel/guild_channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub struct GuildChannel {
7272
/// **Note**: This is only available for text channels.
7373
pub last_pin_timestamp: Option<Timestamp>,
7474
/// The name of the channel. (1-100 characters)
75-
pub name: FixedString<u8>,
75+
pub name: FixedString<u16>,
7676
/// Permission overwrites for [`Member`]s and for [`Role`]s.
7777
#[serde(default)]
7878
pub permission_overwrites: FixedArray<PermissionOverwrite>,

src/model/channel/private_channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ impl PrivateChannel {
200200

201201
/// Returns "DM with $username#discriminator".
202202
#[must_use]
203-
pub fn name(&self) -> FixedString<u8> {
204-
format!("DM with {}", self.recipient.tag()).into()
203+
pub fn name(&self) -> String {
204+
format!("DM with {}", self.recipient.tag())
205205
}
206206

207207
/// Gets the list of [`User`]s who have reacted to a [`Message`] with a certain [`Emoji`].

src/model/guild/automod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pub enum Action {
331331
/// Additional explanation that will be shown to members whenever their message is blocked
332332
///
333333
/// Maximum of 150 characters
334-
custom_message: Option<FixedString<u8>>,
334+
custom_message: Option<FixedString<u16>>,
335335
},
336336
/// Logs user content to a specified channel.
337337
Alert(ChannelId),
@@ -401,7 +401,7 @@ struct RawActionMetadata {
401401
#[serde(skip_serializing_if = "Option::is_none")]
402402
duration_seconds: Option<u64>,
403403
#[serde(skip_serializing_if = "Option::is_none")]
404-
custom_message: Option<FixedString<u8>>,
404+
custom_message: Option<FixedString<u16>>,
405405
}
406406

407407
/// Helper struct for the (de)serialization of `Action`.

src/model/invite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ pub struct InviteStageInstance {
397397
/// The number of users speaking in the Stage
398398
pub speaker_count: u64,
399399
/// The topic of the Stage instance (1-120 characters)
400-
pub topic: FixedString<u8>,
400+
pub topic: FixedString<u16>,
401401
}
402402

403403
enum_number! {

src/model/webhook.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub struct WebhookGuild {
102102
/// The unique Id identifying the guild.
103103
pub id: GuildId,
104104
/// The name of the guild.
105-
pub name: FixedString<u8>,
105+
pub name: FixedString<u16>,
106106
/// The hash of the icon used by the guild.
107107
///
108108
/// In the client, this appears on the guild list on the left-hand side.
@@ -164,7 +164,7 @@ pub struct WebhookChannel {
164164
/// The unique Id of the channel.
165165
pub id: ChannelId,
166166
/// The name of the channel.
167-
pub name: FixedString<u8>,
167+
pub name: FixedString<u16>,
168168
}
169169

170170
#[cfg(feature = "model")]

0 commit comments

Comments
 (0)