-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] [Telegram] Escaping special characters with MarkdownV2 #42697
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
Comments
Thanks for pointing this out, are you open for a PR and add the regex? It would be great if you can add some tests. As this is a bugfix it should be applied against 5.3 branch, thank you. Feel free to ping me in the PR to get a review |
Hello Oskar. Yes, I will prepare a PullRequest. I will try to add a test too. |
…thomas2411) This PR was submitted for the 5.4 branch but it was squashed and merged into the 5.3 branch instead. Discussion ---------- Escape all special characters for parse_mode MARKDOWN_V2 | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #42697 | License | MIT 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. Commits ------- 709981b Escape all special characters for parse_mode MARKDOWN_V2
Closed in #42721 |
In my understanding, this code change replaces all markdown characters when I choose As far as I understand, currently my only option is, to use the legacy markdown option Maybe the escaping should only happen, if |
Symfony version(s) affected: 5.3.6 and below
Description
When sending notification to Telegram that contains any special characters from the list _ * [ ] ( ) ~` > # + - = | { } . ! , except dot which is already escaped, throws exception:
It is for default
parse_mode
orTelegramOptions::PARSE_MODE_MARKDOWN_V2
How to reproduce
Send a notification via telegram with any of the special characters listed above using default
parse_mode
orTelegramOptions::PARSE_MODE_MARKDOWN_V2
Possible Solution
In the documentation of Telegram Bot API https://core.telegram.org/bots/api#markdownv2-style we can see that we need to escape those characters. I have prepared a Regex for this which we can put here https://github.com/symfony/telegram-notifier/blob/5.3/TelegramTransport.php#L85 , replace
str_replace
withpreg_replace
that will escape those characters with\
.If you think this is a good solution please let me know, I will Pull a request.
The text was updated successfully, but these errors were encountered: