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

Fix backslash (\) issue in escape_markdown #2017

Merged
merged 1 commit into from
Jul 30, 2023

Conversation

Artin-GH
Copy link
Contributor

Fix backslash () issue in escape_markdown

When I was using backslash in telebot.formatting.escape_markdown, I was getting an error from the Telegram API.
The regex pattern inside the escape_markdown function was missing a backslash within the brackets.

@Badiboy
Copy link
Collaborator

Badiboy commented Jul 14, 2023

Could you please provide usecase(s) where you got the error that will be fixed with your patch?

@Artin-GH
Copy link
Contributor Author

Artin-GH commented Jul 14, 2023

from telebot import TeleBot
from telebot import types
from telebot.formatting import escape_markdown

tb = TeleBot('0000000000:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')

@tb.message_handler(commands=['start'])
def on_start(message: types.Message):
    tb.send_message(
        message.chat.id, '`{}`'.format(escape_markdown("A message that ends with \\")), 'MarkdownV2')

tb.infinity_polling(skip_pending=True)

You will get something like this when you run the code above and send "/start" to bot:

telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: can't parse entities: Can't find end of Code entity at byte offset 0
"

@Badiboy
Copy link
Collaborator

Badiboy commented Jul 15, 2023

Thank you, looks reasonable.

@coder2020official It's your function - please, confirm update.

@coder2020official coder2020official merged commit e10517e into eternnoir:master Jul 30, 2023
8 checks passed
@coder2020official
Copy link
Collaborator

Sorry for a late response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants