Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| 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
them 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.
Uh oh!
There was an error while loading.Please reload this page.
Thank you@thomas2411. |
bd4a9ba to709981bComparebelmeopmenieuwesim commentedDec 7, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Fixed in#58636 |

In the documentation of Telegram Bot APIhttps://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 replacedhttps://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.