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

Token is incorrectly parsed while using serde #3085

Closed
Freyja-moth opened this issue Dec 28, 2024 · 1 comment
Closed

Token is incorrectly parsed while using serde #3085

Freyja-moth opened this issue Dec 28, 2024 · 1 comment
Labels
bug Something misbehaves or is not working.

Comments

@Freyja-moth
Copy link

Freyja-moth commented Dec 28, 2024

If you are trying to parse Token using serde the bot prefix will be omitted. Since FromStr adds the bot prefix I assume this is a bug.

Should be able to fix it by adding

#[serde(try_from = "String")]
pub struct Token(SecretString);

impl TryFrom<String> for Token {
    type Error = TokenError;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::from_str(&value)
    }
}
@arqunis arqunis added the bug Something misbehaves or is not working. label Jan 3, 2025
arqunis added a commit that referenced this issue Jan 9, 2025
The `Deserialize` implementation neglects to add the `Bot ` prefix to
the string when it is deserialised.

This adds `TryFrom` implementations for `&str` and `String` and tells
serde to deserialise `Token` using the `TryFrom<&str>` implementation,
which will prepend the `Bot ` prefix.

Fixes #3085
@arqunis
Copy link
Member

arqunis commented Jan 9, 2025

Fixed by 5943323.

@arqunis arqunis closed this as completed Jan 9, 2025
arqunis added a commit to arqunis/serenity that referenced this issue Jan 16, 2025
The `Deserialize` implementation neglects to add the `Bot ` prefix to
the string when it is deserialised.

This adds `TryFrom` implementations for `&str` and `String` and tells
serde to deserialise `Token` using the `TryFrom<&str>` implementation,
which will prepend the `Bot ` prefix.

Fixes serenity-rs#3085
mkrasnitski pushed a commit to mkrasnitski/serenity that referenced this issue Feb 1, 2025
The `Deserialize` implementation neglects to add the `Bot ` prefix to
the string when it is deserialised.

This adds `TryFrom` implementations for `&str` and `String` and tells
serde to deserialise `Token` using the `TryFrom<&str>` implementation,
which will prepend the `Bot ` prefix.

Fixes serenity-rs#3085
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something misbehaves or is not working.
Projects
None yet
Development

No branches or pull requests

3 participants
@arqunis @Freyja-moth and others