Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
fabpot merged 0 commits intosymfony:5.3fromthomas2411:notifier_telegram_escape
Aug 25, 2021

Conversation

@thomas2411
Copy link
Contributor

QA
Branch?5.3
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#42697
LicenseMIT

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.

OskarStark reacted with heart emoji
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());
Copy link
Member

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

thomas2411 reacted with thumbs up emoji
Copy link
ContributorAuthor

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.

@fabpotfabpot changed the base branch from5.4 to5.3August 25, 2021 10:34
@fabpot
Copy link
Member

Thank you@thomas2411.

thomas2411 reacted with heart emoji

@fabpotfabpot closed thisAug 25, 2021
@fabpotfabpotforce-pushed thenotifier_telegram_escape branch frombd4a9ba to709981bCompareAugust 25, 2021 10:34
@fabpotfabpot merged commit7d4882c intosymfony:5.3Aug 25, 2021
@thomas2411thomas2411 deleted the notifier_telegram_escape branchAugust 25, 2021 11:08
@fabpotfabpot mentioned this pull requestAug 30, 2021
@belmeopmenieuwesim
Copy link

belmeopmenieuwesim commentedDec 7, 2022
edited
Loading

this PR broke the Telegram formatting entirely for markdown V2. Literally everything stays escaped. If I comment this preg_match the formatting is exactly as it should be. The current code gives this::

image

proArtex and 094ikis09 reacted with thumbs up emojistloyd reacted with thumbs down emoji

@nicolas-grekas
Copy link
Member

Fixed in#58636

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jderussejderussejderusse left review comments

@fabpotfabpotfabpot approved these changes

@OskarStarkOskarStarkAwaiting requested review from OskarStark

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Notifier] [Telegram] Escaping special characters with MarkdownV2

6 participants

@thomas2411@fabpot@belmeopmenieuwesim@nicolas-grekas@jderusse@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp