-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Escape all special characters for parse_mode MARKDOWN_V2 #42721
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
Conversation
@@ -82,7 +82,7 @@ protected function doSend(MessageInterface $message): SentMessage | |||
|
|||
if (!isset($options['parse_mode']) || TelegramOptions::PARSE_MODE_MARKDOWN_V2 === $options['parse_mode']) { | |||
$options['parse_mode'] = TelegramOptions::PARSE_MODE_MARKDOWN_V2; | |||
$options['text'] = str_replace('.', '\.', $message->getSubject()); | |||
$options['text'] = preg_replace('/([\[_\*\[\]\(\)~`>#\+-=\|{}\.!])/m', '\\\\$1', $message->getSubject()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\[
is referenced twice.
IIRC you don't have to escape everything
the m
could be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, indeed, I will remove it.
src/Symfony/Component/Notifier/Bridge/Telegram/TelegramTransport.php
Outdated
Show resolved
Hide resolved
Thank you @thomas2411. |
bd4a9ba
to
709981b
Compare
Fixed in #58636 |
In the documentation of Telegram Bot API https://core.telegram.org/bots/api#markdownv2-style we can see that we need to escape more characters _ * [ ] ( ) ~ ` > # + - = | { } . !.
I have prepared a Regex for this and replaced https://github.com/symfony/telegram-notifier/blob/5.3/TelegramTransport.php#L85
I have also changed test used for escaping dot to a test that checks escaping all those characters.