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 EscapeText for MarkdownV2. #604

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

navossoc
Copy link

@navossoc navossoc commented Nov 2, 2022

This pull request is pretty straight forward...

Telegram documentation says:

Any character with code between 1 and 126 inclusively can be escaped anywhere with a preceding '' character, in which case it is treated as an ordinary character and not a part of the markup. This implies that '\' character usually must be escaped with a preceding '\' character.

Source: https://core.telegram.org/bots/api#markdownv2-style

So here goes a simple sample program to simulate the bug:

package main

import (
	"fmt"

	tg "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)

func main() {
	fmt.Println(tg.EscapeText(tg.ModeMarkdownV2, `a\b`))
	fmt.Println(tg.EscapeText(tg.ModeMarkdownV2, `a\(b)c`))
}

Before the fix:

a\b
a\\(b\)c

After the fix:

a\\b
a\\\(b\)c

In the first example:
the message will be send like "ab" (the slash will disappear)

In the second example:
the message will not be sent, it will error out something like this:
Bad Request: can't parse entities: Character '(' is reserved and must be escaped with the preceding '\'

It's a small fix, but an important one.

[]'s

@navossoc
Copy link
Author

Is this package still maintained?

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.

None yet

1 participant