fix(webhook): keep line breaks in Telegram rich messages (#39650)

Restore the old layout by converting line breaks (`\n`, `\r\n`, `\r`) to `<br>`
in `createTelegramPayloadHTML`, after sanitizing, covering every Telegram
payload type at once.

Fixes https://github.com/go-gitea/gitea/issues/39649
This commit is contained in:
KShot authored and GitHub committed 2026-10-08 09:16:17 +00:00
1 parent a0b9ce05c4
commit 02da29f2da
2 files changed
+17 -18

No files matched your search

+4 -1
View File
@@ -201,9 +201,12 @@ func (telegramConvertor) WorkflowJob(p *api.WorkflowJobPayload) (TelegramPayload
func createTelegramPayloadHTML(msgHTML string) TelegramPayload {
// https://core.telegram.org/bots/api#formatting-options
sanitized := strings.TrimSpace(string(markup.Sanitize(msgHTML)))
// Rich messages collapse bare newlines like HTML, so keep line breaks as <br>.
sanitized = strings.NewReplacer("\r\n", "<br>", "\r", "<br>", "\n", "<br>").Replace(sanitized)
return TelegramPayload{
RichMessage: InputRichMessage{
HTML: strings.TrimSpace(string(markup.Sanitize(msgHTML))),
HTML: sanitized,
},
}
}