From 3c4192ebf6a32e30cdd23a9644c2ceca72a006fa Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 7 Jul 2022 01:47:50 +0300 Subject: [PATCH] Fix message html entities escaping when sending to Telegram (#1855) --- bridge/telegram/html.go | 13 +++++++++++-- bridge/telegram/telegram.go | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bridge/telegram/html.go b/bridge/telegram/html.go index 41326f6f..4aa9fd3a 100644 --- a/bridge/telegram/html.go +++ b/bridge/telegram/html.go @@ -2,7 +2,6 @@ package btelegram import ( "bytes" - "html" "github.com/russross/blackfriday" ) @@ -24,10 +23,16 @@ func (options *customHTML) Paragraph(out *bytes.Buffer, text func() bool) { func (options *customHTML) BlockCode(out *bytes.Buffer, text []byte, lang string) { out.WriteString("
")
 
-	out.WriteString(html.EscapeString(string(text)))
+	out.WriteString(string(text))
 	out.WriteString("
\n") } +func (options *customHTML) CodeSpan(out *bytes.Buffer, text []byte) { + out.WriteString("") + out.WriteString(string(text)) + out.WriteString("") +} + func (options *customHTML) Header(out *bytes.Buffer, text func() bool, level int, id string) { options.Paragraph(out, text) } @@ -42,6 +47,10 @@ func (options *customHTML) BlockQuote(out *bytes.Buffer, text []byte) { out.WriteByte('\n') } +func (options *customHTML) LineBreak(out *bytes.Buffer) { + out.WriteByte('\n') +} + func (options *customHTML) List(out *bytes.Buffer, text func() bool, flags int) { options.Paragraph(out, text) } diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index 25225416..43cb818f 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -101,7 +101,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) { } if b.GetString("MessageFormat") == HTMLFormat { - msg.Text = makeHTML(msg.Text) + msg.Text = makeHTML(html.EscapeString(msg.Text)) } // Delete message