From 06a21ba9e1e18dfa5cd91ecc24b820f47d11b7e4 Mon Sep 17 00:00:00 2001 From: Sprite Date: Thu, 16 Dec 2021 00:28:52 +0800 Subject: [PATCH 1/2] Skip the `language` field of `MessageEntityKind::Pre` if it is `None` --- src/types/message_entity.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/types/message_entity.rs b/src/types/message_entity.rs index 1f4873c8..55facb77 100644 --- a/src/types/message_entity.rs +++ b/src/types/message_entity.rs @@ -44,6 +44,7 @@ impl MessageEntity { } } +#[serde_with_macros::skip_serializing_none] #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] #[serde(tag = "type")] @@ -104,4 +105,20 @@ mod tests { .unwrap() ); } + + #[test] + fn pre_with_none_language() { + use serde_json::to_string; + + assert_eq!( + to_string(&MessageEntity { + kind: MessageEntityKind::Pre { language: None }, + offset: 1, + length: 2, + }) + .unwrap() + .find("language"), + None + ); + } } From 234ac365db2bc2f8c688153d91b278a2b0517a91 Mon Sep 17 00:00:00 2001 From: Sprite Date: Thu, 16 Dec 2021 00:41:04 +0800 Subject: [PATCH 2/2] Update changelog and comment the PR link in the test --- CHANGELOG.md | 2 ++ src/types/message_entity.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 887e19ae..e63789b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,12 +52,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Make `SendPoll::poll_` optional ([#133][pr133]) - Bug with `caption_entities`, see issue [#473][issue473] - Type of response for `CopyMessage` method ([#141](pr141), [#142](pr142)) +- Bad request serialization when the `language` field of `MessageEntityKind::Pre` is `None` ([#145](pr145)) [pr119]: https://github.com/teloxide/teloxide-core/pull/119 [pr133]: https://github.com/teloxide/teloxide-core/pull/133 [pr141]: https://github.com/teloxide/teloxide-core/pull/141 [pr142]: https://github.com/teloxide/teloxide-core/pull/142 [pr143]: https://github.com/teloxide/teloxide-core/pull/143 +[pr145]: https://github.com/teloxide/teloxide-core/pull/145 [issue473]: https://github.com/teloxide/teloxide/issues/473 [issue427]: https://github.com/teloxide/teloxide/issues/427 diff --git a/src/types/message_entity.rs b/src/types/message_entity.rs index 55facb77..cd8b6278 100644 --- a/src/types/message_entity.rs +++ b/src/types/message_entity.rs @@ -106,6 +106,7 @@ mod tests { ); } + // https://github.com/teloxide/teloxide-core/pull/145 #[test] fn pre_with_none_language() { use serde_json::to_string;