Skip to content

Commit a25c76e

Browse files
authored
Fix Empty Captions not Being Passed by Bot.copy_message (python-telegram-bot#2651)
1 parent 0c50850 commit a25c76e

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The following wonderful people contributed directly or indirectly to this projec
3939
- `daimajia <https://github.com/daimajia>`_
4040
- `Daniel Reed <https://github.com/nmlorg>`_
4141
- `D David Livingston <https://github.com/daviddl9>`_
42+
- `DonalDuck004 <https://github.com/DonalDuck004>`_
4243
- `Eana Hufwe <https://github.com/blueset>`_
4344
- `Ehsan Online <https://github.com/ehsanonline>`_
4445
- `Eli Gao <https://github.com/eligao>`_

telegram/bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5296,7 +5296,7 @@ def copy_message(
52965296
'disable_notification': disable_notification,
52975297
'allow_sending_without_reply': allow_sending_without_reply,
52985298
}
5299-
if caption:
5299+
if caption is not None:
53005300
data['caption'] = caption
53015301
if caption_entities:
53025302
data['caption_entities'] = caption_entities

tests/test_bot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,8 @@ def assertion(url, data, *args, **kwargs):
20242024

20252025
@flaky(3, 1)
20262026
@pytest.mark.parametrize('json_keyboard', [True, False])
2027-
def test_copy_message(self, monkeypatch, bot, chat_id, media_message, json_keyboard):
2027+
@pytest.mark.parametrize('caption', ["<b>Test</b>", '', None])
2028+
def test_copy_message(self, monkeypatch, bot, chat_id, media_message, json_keyboard, caption):
20282029
keyboard = InlineKeyboardMarkup(
20292030
[[InlineKeyboardButton(text="test", callback_data="test2")]]
20302031
)
@@ -2033,7 +2034,7 @@ def post(url, data, timeout):
20332034
assert data["chat_id"] == chat_id
20342035
assert data["from_chat_id"] == chat_id
20352036
assert data["message_id"] == media_message.message_id
2036-
assert data["caption"] == "<b>Test</b>"
2037+
assert data.get("caption") == caption
20372038
assert data["parse_mode"] == ParseMode.HTML
20382039
assert data["reply_to_message_id"] == media_message.message_id
20392040
assert data["reply_markup"] == keyboard.to_json()
@@ -2046,7 +2047,7 @@ def post(url, data, timeout):
20462047
chat_id,
20472048
from_chat_id=chat_id,
20482049
message_id=media_message.message_id,
2049-
caption="<b>Test</b>",
2050+
caption=caption,
20502051
caption_entities=[MessageEntity(MessageEntity.BOLD, 0, 4)],
20512052
parse_mode=ParseMode.HTML,
20522053
reply_to_message_id=media_message.message_id,

0 commit comments

Comments
 (0)